[R] Boxplot Fill Pattern
R. Michael Weylandt
michael.weylandt at gmail.com
Thu Mar 8 20:22:41 CET 2012
On Thu, Mar 8, 2012 at 1:08 PM, Gabriel Yospin <yosping at gmail.com> wrote:
> Hello R Help!
Hello Gabe Yospin! (I feel like I should start playing some arena rock
anthem now ;-) )
>
> I would like to make a legible boxplot of tree growth rates for each of
> seven tree species at each of seven different sites. It's a lot of data to
> put on one figure, I know. I made a beautiful, interpretable figure using
> color, but my target journal can't deal with color figures. I can use seven
> shades of grey to fill the boxes, but the figure then becomes
> uninterpretable - the colors of adjacent boxes are too similar. I cannot
> figure out how to add a pattern, hatching, or cross-hatching to the boxes.
>
> I see that in 2003 Professor Ripley confirmed that one cannot hatch
> boxplots:
>
> http://tolstoy.newcastle.edu.au/R/help/03a/2622.html
>
> Is this still true? If so, does anyone have a suggestion for how to make
> this figure interpretable in black and white? Should I pick a different
> target journal?
>
I don't think you'd need to change journals just for graphical styles:
do it for much less important things, like impact factor. It sounds
like the idea of small multiples might help here: I'm not a lattice
pro, but here's something you could do in ggplot2 (and I know it's
doable in lattice as well):
I'm gonna put new lines in all your species names since space will be
at a premium:
levels(datnew.lo$sp) <- gsub(" ", "\n", levels(datnew.lo$sp))
library(ggplot2)
ggplot(datnew.lo, aes(x = sp, y = ga)) + geom_boxplot() +
facet_wrap(~site, nrow = 2) + opts(axis.text.x=theme_text(angle=45,
size = 7))
Others with more ggplot / lattice - fu than I can help you tweak this
but hopefully this is a start.
Michael
> Many thanks,
>
> Gabe
>
> Functional code to make the color figure with fake data follows:
> #
> leg.txt = c("Abies grandis","Acer macrophyllum","Calocedrus
> decurrens","Pinus ponderosa","Pseudotsuga meziensii","Quercus
> garryana","Quercus kelloggii")
> site.txt = c("Brownsville","Chip Ross","Finley","Jim's
> Creek","Lowell","Mount Pisgah","South Eugene")
> colors = c("gray","red","white","blue","yellow","purple","orange")
> # Fake data here:
> site = rep(site.txt, each = 21)
> sp = rep(rep(leg.txt, each = 3), times = 7)
> ga = runif(147, 0, 20)
> datnew.lo = data.frame(site,sp,ga)
> # Now make the plot:
> boxplot(ga~sp*site,data=datnew.lo, range = 1,
> col = colors,
> ylim = c(0,30),
> xaxt = "n",
> xlab = "Site",
> ylab = "Basal Area Growth Increment",
> main = "Basal Area Growth Increment by Site and Species")
> axis(1, at = c(4,11,18,25,32,39,46),
> labels = site.txt,
> )
> abline(v = 7.5, lty = 3)
> abline(v = 14.5, lty = 3)
> abline(v = 21.5, lty = 3)
> abline(v = 28.5, lty = 3)
> abline(v = 35.5, lty = 3)
> abline(v = 42.5, lty = 3)
> legend("topright", legend = leg.txt, fill = colors, bg = "white")
Thanks for the great reproducible example! Made this much easier and more fun.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list