[R] Patterned shading in ggplot

Paul Chatfield p.s.chatfield at rdg.ac.uk
Wed Nov 4 11:17:12 CET 2009


Am trying to produce a graph which prints out well in black and white using
ggplot2.  I have the following example set up nicely, but want to shade the
red bars in one pattern and the blue in another so they print out clearly. 
I tried changing colours to 1 light, 1 dark, but then the overlapping colour
looks virtually identical to the darker one.  I noted the option density in
barplot, but couldn't get this to work in ggplot.  I could just replot this
as density plots using kernel smoothing, but quite like this format for the
data I have.  Any help much appreciated.

library(ggplot2)
xy<-data.frame(x=c(rnorm(1000), rnorm(1000,2,1)), grp=as.factor(rep(1:2,
each=1000)))
ggplot(xy, aes(x=x, fill=grp, group=grp)) +
geom_histogram(binwidth=0.5,colour="black",position = "identity", alpha =
0.5) + 
scale_fill_manual(values = c("red", "blue"))
-- 
View this message in context: http://old.nabble.com/Patterned-shading-in-ggplot-tp26193795p26193795.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list