How to remove outliers in boxplot in R? [duplicate

2019-03-11 00:04发布

问题:

Possible Duplicate:
Changing the outlier rule in a boxplot

I need to visualize my result using box-plot.

x<-rnorm(10000)
boxplot(x,horizontal=TRUE,axes=FALSE)

How can i filter outliers during visualisation?

(1) So that i can have full image on screen without having ugly outliers.

http://postimage.org/image/szzbez0h1/a610666d/

(2) Is there any way to show outliers upto certain range? http://postimage.org/image/np28oee0b/8251d102/

Regards

回答1:

See ?boxplot for all the help you need.

 outline: if ‘outline’ is not true, the outliers are not drawn (as
          points whereas S+ uses lines).

boxplot(x,horizontal=TRUE,axes=FALSE,outline=FALSE)

And for extending the range of the whiskers and suppressing the outliers inside this range:

   range: this determines how far the plot whiskers extend out from the
          box.  If ‘range’ is positive, the whiskers extend to the most
          extreme data point which is no more than ‘range’ times the
          interquartile range from the box. A value of zero causes the
          whiskers to extend to the data extremes.

# change the value of range to change the whisker length
boxplot(x,horizontal=TRUE,axes=FALSE,range=2)