Skip to content

Bar Plot ggplot2 Filling bars with cross hatching

14 messages · Greg Snow, stephen sefick, Duncan Murdoch +4 more

#
#I am putting a test together for an introductory biology class and I
would like to put different cross hatching inside of each bar for the
bar plot below

color <- c("Brightly Colored", "Dull", "Neither")
lizards <- c(277, 70, 3)
liz.col <- data.frame(color, lizards)
qplot(color, lizards, data=liz.col, geom="bar", ylab="Observed
Matings", main="Counts Out of 350 Aquariums", ylim=c(0,400),
fill=color)+scale_y_continuous(breaks=c(0, 70, 277, 350))


Thanks
#
Also notice that the q in Aquarium is hidden.  Is there a way to make
this not happen?
thanks

Stephen Sefick
On Wed, Jan 14, 2009 at 10:18 PM, stephen sefick <ssefick at gmail.com> wrote:

  
    
#
Hi Stephen,
ggplot2 uses the grid package to do all the drawing, and currently
grid doesn't support cross-hatching, so unfortunately there's no way
to do this in ggplot2.

Regards,

Hadley
#
This will be fixed in the next version, but until then you can do
title = "Aquarium\n"

Hadley
On Wed, Jan 14, 2009 at 9:24 PM, stephen sefick <ssefick at gmail.com> wrote:

  
    
4 days later
#
I think the fact that the grid package does not support cross-hatching is a feature not a bug (or deficiency), and I hope that this is not "fixed".  Tufte's book (The Visual Display of Quantitative Information) has a section on why cross-hatching should be avoided (unless of course your goal is to induce nausea in the observer rather than convey information).

I would edit Hadley's statement below to say "fortunately there's no way to do this in ggplot2".
#
what is your suggestion for distinguishing between many bars without
color?  I have grown up in the time of standarized tests - good or bad
I never felt nauseous.

Stephen
On Mon, Jan 19, 2009 at 5:20 PM, Greg Snow <Greg.Snow at imail.org> wrote:

  
    
#
On 19/01/2009 7:36 PM, stephen sefick wrote:
Use gray levels or labels.  If "many" is bigger than 5, it's not going 
to be easy, whatever method you are using.

Duncan Murdoch
#
On 20/01/2009, at 1:36 PM, stephen sefick wrote:

            
Exactly.  Sometimes colour printing can be expensive.
Ni moi non plus.

		cheers,

			Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
#
If classic graphics is ok try this which uses hatches and different
shades of grey:

barplot(lizards, names.arg = color, col = grey(c(.2, .5, 1)), density = 20,
    angle = c(45, -45, 0), legend = color)
On Wed, Jan 14, 2009 at 10:18 PM, stephen sefick <ssefick at gmail.com> wrote:
#
On 20/01/2009, at 1:46 PM, Duncan Murdoch wrote:

            
I disagree.  Grey levels suck; labels are a kludge.  It is an issue
	for ``many'' == 2, for which crosshatching works perfectly.

		cheers,

			Rolf
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
#
On 19-Jan-09, at 4:59 PM, Rolf Turner wrote:

            
I believe Tufte had negative things to say about barplots, hatched or  
not.  He said something to the effect
of "Why use a two-dimensional rectangle to represent a one- 
dimensional data point?"

What about a dotplot with a different symbol for each of what would  
have been hatched rectangles?
That reduces the ink/information ratio (which I believe was also a  
concern of Tufte's).

Don
Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
College of Forest Resources
CSES Climate Impacts Group
University of Washington

desk: 206-732-7824
cell: 206-321-5966
dmck at u.washington.edu
donaldmckenzie at fs.fed.us
#
Rolf Turner wrote:
Could you show an example?

There are several BW examples in example(barplot), and the gray ones 
look better on screen than the cross-hatched one.  (Not to say it makes 
a very good choice of cross-hatching, but I suspect the gray examples 
will look better than any 5 cross-hatch patterns.)  I haven't tried 
printing the examples, so I'm not sure the gray would reproduce well on 
paper; I wouldn't try to print those 5 gray levels on a typical printer.

Duncan Murdoch
#
My feeling is that the best cross-hatching is probably going to be
more aesthetically pleasing than the best solid greys (see e.g.
http://www.dannygregory.com/2005/09/cross_hatching.php).  However,
doing cross hatching well is far more difficult than doing grey well,
and for really nice cross-hatching I suspect you also need a high
quality printer.   It is also a challenging problem to come up with an
algorithm for generating perceptually uniform sets of cross-hatchings.
 I suspect there is some work on this area in vis/infovis, but I
haven't find it in a few minutes of casual searching.

Hadley

Hadley
#
The best thing to do really depends on your situation and what question you are trying to answer with your plot.  

Shades of grey has been mentioned, and in some cases that works, but you then run into the problem (same problem with colors and hatching density) of figuring out which bars to make light and which dark since a plot can have a very different visual impact depending on that choice.

Sometimes reordering and/or grouping/regrouping bars in a barplot can convey the information with the need for fewer visual distinguishers.  Dotplots have also been mentioned already, they are often an improvement on a barplot.  You can use different symbols for the dots (or even letters if overlap is small enough and the letters give more information) and labeling and grouping are more natural.  Sometimes a line plot is an appropriate alternative to a barplot.

Also take into account how the plot will be used/displayed, others have mentioned that what looks good on screen may not print out well (also true of cross-hatching).  I have seen some overhead projectors where the slide clearly had black and grey sections, but when projected, all the grey was black as well.  If this is something that will be photocopied, then colors/shades/hatches can change in that process and not be distinguishable.

Often the best strategy is to make multiple variations of a graph, then show them to someone else for an outside opinion of which best convey the information.

If you tell us a bit more about the specifics of the project, we may have more or better suggestions.