I am trying to draw a box and whisker plot in R. My code is below. At the moment, because I only have data for two months in one of the two sites, the bars are wider for that site (because the third level of month is dropped).
Instead, I would like the same pattern of boxes for site A
as there is for site B
(i.e. with space for an empty box on the right-hand side). I can easily do this with drop=TRUE
when I only have one factor but do not seem to be able to do it with the "filling" factor.
Month=rep(c(rep(c("Jan","Feb"),2),"Mar"),10)
Site=rep(c(rep(c("A","B"),each=2),"B"),10)
factor(Month)
factor(Site)
set.seed(1114)
Height=rnorm(50)
Data=data.frame(Month,Site,Height)
plot = ggplot(Data, aes(Site, Height)) +
geom_boxplot(aes(fill=Month, drop=TRUE), na.rm=FALSE)
plot
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…