r - Set ylim() automatically -
here data work with.
df <- data.frame(x1=c(234,543,342,634,123,453,456,542,765,141,636,3000),x2=c(645,123,246,864,134,975,341,573,145,468,413,636))
if plot these data, produce simple scatter plot obvious outlier:
plot(df$x2,df$x1)
then can write code below remove y-axis outlier(s).
plot(df$x2,df$x1,ylim=c(0,800))
so question is: there way exclude obvious outliers in scatterplots automatically? ouline=f
if plot, say, boxplots example. knowledge, outline=f
doesn't work scatterplots.
this relevant because have hundreds of scatterplots , want exclude obvious outlying data points without setting ylim(...)
each individual scatterplot.
you write function returns index of define obvious outlier. use function subset data before plotting.
here observations "a" exceeding 5 * median of "a" excluded.
df <- data.frame(a = c(1,3,4,2,100), b=c(1,3,2,4,2)) f <- function(x){ which(x$a > 5*median(x$a)) } with(df[-f(df),], plot(b, a))
Comments
Post a Comment