Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a boxplot in RStudio using only min, max, median, lower fourth, upper fourth, and outliers?

Tags:

r

I'm trying to create a boxplot, but the only data I know is the min, max, median, lower fourth, upper fourth, and the outliers. This is my data:

  • Min: 188.1
  • Max: 230.5
  • Lower Fourth: 196.0
  • Median: 202.2
  • Upper Fourth: 216.8
  • Outliers: 125.8, 250.2

I have been able to create the boxplot with:

dat<-read.table(text = "188.1 196.0 202.2 216.8 230.5")
dat<-t(dat)
bxp(list(stats=dat, n=rep(10, ncol(dat))))

But I don't know how to give it the outliers and make it show them. I've only found questions asking how to get rid of the outliers, but I need to know how to show them. How do I do this?

like image 736
K.R. Avatar asked Sep 06 '25 06:09

K.R.


1 Answers

Just add additional arguments out and groups to the list of stats summaries you pass into bxp():

bxp(list(stats = dat, n = rep(10, ncol(dat)),
         out = c(125.8, 250.2), groups = c(1,1)))

enter image description here


To see how you might have learned that yourself, check out ?bxp, which includes this description of its first argument:

z: a list containing data summaries to be used in constructing
   the plots.  These are usually the result of a call to
   ‘boxplot’, but can be generated in any fashion.

Hmm. That looks promising. To learn more about exactly what sort of data summaries result from a call to boxplot(), we can check out the "Value" section ?boxplot, where we find that it returns a list with the following components (among others):

  out: the values of any data points which lie beyond the extremes
       of the whiskers.

group: a vector of the same length as ‘out’ whose elements indicate
       to which group the outlier belongs.
like image 168
Josh O'Brien Avatar answered Sep 07 '25 21:09

Josh O'Brien