Why does the following code produce different figures? (required package: plotrix)
boxplot(mpg~cyl, data =mtcars)
gap.boxplot(mpg~cyl, data =mtcars)
But the following code produces the same figures?
boxplot(mtcars$mpg)
gap.boxplot(mtcars$mpg)
My end goal is to produce a boxplot that has whiskers that represent 5% and 95% quantiles and able to add a gap to show extreme values. I know how to edit boxplot.default to get 5% and 95% Whiskers but I can not get my figure to agree with my data when using gap.boxplot
. Any tips will help since I am new to R. Thank you.
Edit: The code below also produces the same figure so this leads me to believe it has something to do with how the data is arranged
twovec<-list(vec1=c(rnorm(30),-6),vec2=c(sample(1:10,40,TRUE),20))
boxplot(twovec)
gap.boxplot(twovec)
Edit2: gap.boxplot does not work when the number of "groups" is different than the number of "outputs". This is because gap.boxplot figures out the groups (bxgap$group <- at
) different than boxplot.default. So it ends up assigning the outliers to the incorrect groups. I am still not sure how to fix this so any help would be appreciated. If I figure this out I will either post it as a solution or delete this post.
> summary(boxplot(mpg~cyl, data =mtcars))
Length Class Mode
stats 15 -none- numeric
n 3 -none- numeric
conf 6 -none- numeric
out 2 -none- numeric
group 2 -none- numeric
names 3 -none- character
> summary(gap.boxplot(mpg~cyl, data =mtcars))
Length Class Mode
stats 15 -none- numeric
n 3 -none- numeric
conf 6 -none- numeric
out 2 -none- numeric
group 3 -none- numeric
names 3 -none- character