11

As ggplot2 produces nice colored graphs but sometimes it is required to have black and white graphs with pattern fills. I wonder how to do this in ggplot2, say for this code:

ggplot(diamonds, aes(cut, fill=cut)) + geom_bar()

Edit

Is there any function in R to do pattern fills for graphs?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
  • 3
    A quick Google search reveals [this](http://www.mail-archive.com/r-help@r-project.org/msg74619.html) and quite a few other results that note that grid doesn't support patterned fills of polygons. – joran Sep 30 '11 at 00:30
  • Any other R function having pattern fills capabilities? – MYaseen208 Sep 30 '11 at 02:16
  • 1
    Not off the top of my head. If you're looking into this because the graph will be printed in black and white, consider simply using a greyscale color palette. – joran Sep 30 '11 at 02:54
  • 2
    a proof-of-concept for grid rectangles is in `gridExtra`, `example(patternGrob)`. Not that I'd recommend it though. – baptiste Sep 30 '11 at 22:04
  • 2
    the `gridSVG` package seems to be fairly close to providing a solution using `grid.garnish()` and fills defined as in this page http://www.w3.org/TR/SVG/pservers.html – baptiste Sep 30 '11 at 22:38
  • I've added an answer in the following thread that provides a few approaches to adding pattern fills: http://stackoverflow.com/a/20426482/2653210 – Docconcoct Nov 10 '14 at 03:23

1 Answers1

3

have a look at the 6th plot of example(barplot).

EDi
  • 13,160
  • 2
  • 48
  • 57