Showing posts with label colours. Show all posts
Showing posts with label colours. Show all posts

Monday, June 4, 2012

Boxplot in facets with different background colours

boxplots with facets and different background colours

  • x contains the vars sex, heightsds and riskgroup
  • rg contains a vars riskgroup, min (which is -inf in all cases) and max (which is inf in all cases); these define the backgroup colors for the different facets
p <- ggplot(x)
p +
  geom_boxplot(aes(x=sex,y=heightsds,color=sex),fill="grey",notch=T,alpha=1) +
  geom_rect(data=rg,aes(fill=riskgroup,xmin=min,ymin=min,xmax=max,ymax=max),alpha=0.15) +
  facet_wrap(~riskgroup) +
  scale_fill_manual(values=c("darkseagreen1","lightgreen","gold","firebrick")) +
  ylab("Adult Height - Height SDS") + xlab("Sex") +
  opts(panel.background=theme_rect(colour=NA),legend.position="none")