[R] Patterned shading in ggplot

hadley wickham h.wickham at gmail.com
Wed Nov 4 15:00:56 CET 2009


Hi Paul,

You might want to try the gray colour scale - scale_fill_grey()

Unfortunately grid (the underlying graphics library that ggplot2 uses)
does not currently support patterns.

Hadley


On Wed, Nov 4, 2009 at 4:17 AM, Paul Chatfield <p.s.chatfield at rdg.ac.uk> wrote:
>
> 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.
>
> ______________________________________________
> 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.
>



-- 
http://had.co.nz/




More information about the R-help mailing list