Note that there are some explanatory texts on larger screens.

plurals
  1. POR ggplot - Coordinates transform (square root) with boxplot
    primarykey
    data
    text
    <p>I have a couple of box and whisker plots in R. In both, the x-axis corresponds to one categorical variable whilst the grouping colours correspond to the other.</p> <p>If I draw both plots with an untransformed y-axis, they are both fine. However, if I try to square-root transform the y-axis (using: coord_trans(y = "sqrt")), one of those graph is still fine whilst the other drops the lines corresponding to the median in most boxes (except those for which there are only two groups and where the boxes are therefore slightly wider, see "Numbers" 1 and 2 on the first plot). Further, for the graph that does not draw properly, if I reduce the number of categories on my x-axis (hence getting the boxes wider again), the median lines appear again.</p> <p>Is this a bug with coord_trans (if so, how can I get around it) or a problem with my code?</p> <p>Thank you very much for any suggestion.</p> <pre><code>library(car) library(gplots) library(plyr) library(ggplot2) library(gridExtra) library(gdata) Category=factor(c(rep(1, times =3240), rep(2, times =2160)), labels=c("A","B"), levels=c(1,2)) ID=factor(rep(seq(from = 1, to = 45),each = 120)) Months=factor(rep(seq(from = 1, to = 3), each = 40, times = 45), labels=c("Jan","Feb","Mar"),levels=c(1:3)) Obs=rnorm(5400, mean=25, sd=15) Data=data.frame(Category,ID,Months,Obs) Data=subset(Data, (Data$Category=="B") | !(Data$ID%in%c(1,2)) | (Data$Months%in%c("Jan","Feb"))) for (j in 1:2) { sel=which(Data$Category==unique(levels(Data$Category))[j]) Observ=Data$Obs[sel] Month=Data$Months[sel] Number=droplevels(Data$ID[sel]) Number=droplevels(Number) Data_used=data.frame(Number,Month,Observ) plot1 = ggplot(Data_used, aes(Number, Observ)) + geom_boxplot(aes(fill=Month, drop=FALSE), na.rm=TRUE) + scale_y_continuous(breaks = c(0,20,40,60,80,100), limits=c(0,115)) + coord_trans(y = "sqrt") plot(plot1) } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload