How to Add Texture to Histogram in ggplot2

5,381 views
Skip to first unread message

钟志强

unread,
Jul 22, 2016, 6:40:42 AM7/22/16
to ggplot2

Dear all,


How can I add texture to histogram when I use ggplot to draw histogram?
What I want is shown below:



Thanks

zhiqiang

Greg Snow

unread,
Jul 22, 2016, 11:24:06 AM7/22/16
to 钟志强, ggplot2
First you should ask yourself why you want to do this.  

Some of us consider the fact that this is not easy to be a feature.

When you use patterns like that then you run the risk of what is called the Moire effect, where unintended patterns and sometimes even the illusion of movement (which can even cause nausea, probably not the desired effect of your graph) appear due to differences in resolutions or the eye having a hard time switching between the frequencies.  For example, in the example plot that you show, I can see something like a horizontal line through the bars just below the 0.4 mark (that line is thicker in the bars with horizontal lines, the dots are bolder in the dotted bar, the crosshatched bar is actually lighter, and the diagonal lines have a little jump).  The eye is drawn to this line that is probably not intentional (and will probably be in a different place on a different device, or if you had exported using a slightly different resolution).  

You should consider alternatives.  The simplest alternative is solid blocks of different colors, but with color blindness, people photocopying, using e-readers, etc. Color is not always the best option, though colors that become distinct shades of grey are possible.  For a bar plot, you might consider a dot plot instead, then distinctions can be  made using symbols instead of patterns or colors.

If you think through this and are still convinced that you want the patterns then your best option may be to create the plot with distinct colors, then use an external program such as Imagemagick, Inkscape, or Gimp (or others) to replace the colors with patterns.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

钟志强

unread,
Jul 22, 2016, 11:42:50 AM7/22/16
to ggplot2, zqzho...@gmail.com
Hi Greg,

Thanks for your reply :)

I found it is difficult to add texture to bar in ggplot2.
So I decide to use another tool to draw bar, it also has the effect you described above.

zhiqiang

在 2016年7月22日星期五 UTC+8下午11:24:06,Greg Snow写道:

Brian Shine

unread,
Jul 22, 2016, 12:41:57 PM7/22/16
to 钟志强, Dr Brian Shine, ggplot2
For some situations, e.g., printing in black and white, it may be the best of a poor set of options!  I have done it once, but it was very fiddly.

Brian

Aurélien Ginolhac

unread,
Jul 25, 2016, 11:03:02 AM7/25/16
to ggplot2, zqzho...@gmail.com
Reply all
Reply to author
Forward
0 new messages