Reputation: 111
I'm trying to do a scatterplot in R and would love to remove an outlier I've already identified.
My plot function:
attach(L)
plot(independent variable, dependent variable, main="TITLE", xlab="x-axis label", ylab="y-axis label", pch=18, col="blue")
text(independent variable, dependent variable, data label, cex=0.6, pos=4, col="red")
My best-fit line:
abline(lm(dependent variable ~ independent variable))
Is there a simple way I can remove "ISR" on the graph below without installing any additional packages? Thanks!
Upvotes: 0
Views: 26873
Reputation: 8252
1) If you just want to exclude $y$ values above (or below) some specific value, use the ylim
argument to plot. e.g. ,ylim=c(0,20)
should work for the above plot.
2) You say you've already "identified" the outliers. If you have a logical variable or expression that indicates the outliers, you can use that in your plot.
e.g. consider:
# let's make a small data example
x=1:10
y=rnorm(10)
y[5]=30
par(mfrow=c(1,2))
plot(x,y) # outlier problem
yout=y>5 # some logical rule for identifying an outlier
plot(x[!yout],y[!yout]) # toss them out
Upvotes: 2