Stacked bar plot filled with symbols/lines

1,909 views
Skip to first unread message

zelfortin

unread,
Aug 1, 2013, 2:06:42 PM8/1/13
to ggp...@googlegroups.com
Hi all,

I have stacked bar plots that I want to fill with symbols/ lines rather than colors. Here is what my script looks like to fill with colors:

Coul <- c("#990000","#FF3300","#FF6633","#999999","#CCFF99","#33CC00")

Plot1 <- qplot(factor(Model),data=Best, geom="bar",fill=factor(Best$New.Curve), xlab="Model", ylab="Count") +
labs(title=paste("Best models by country for ", File[e], sep="")) +
scale_fill_manual(values=Coul)

Plot1

So I'm looking to get something more like this:
http://i.stack.imgur.com/62pvM.png

Rather than what I get:


Any help would be much appreciated.

Cheers

JM

Greg Snow

unread,
Aug 1, 2013, 3:20:55 PM8/1/13
to zelfortin, ggplot2
The human eye-brain combination tends to focus on areas of contrast (change from one color/shade to another).  When you fill boxes with a solid color (or shade of grey) then the focus is on the boundaries, but when you fill a box with diagonal lines, hash marks, grids, symbols, etc. then the eye is often drawn to the contrast within the box rather than the boundary of the box and this will make it harder for the viewer of the graph to make meaningful comparisons.  This can be a "Fuzzy Box" effect where the size of the box is not interpreted well.  It can even cause a Moire effect where parts of the plot appear to move, even causing motion sickness in some viewers (see the book by Tufte).

The use of the diagonal lines and other patterns date back to the days when the best way to get a color graphic was to use a mechanical pen plotter (a mechanical arm moved a pen around on the paper) and it was impractical to completely fill the area (a high density would do it in theory, but it was really slow (making all the other people waiting to plot something mad) and often tore holes in the paper).  With modern monitors and printers it is better to use solid fills if you are doing a bar chart.

If you are trying to find an alternative to using color (because you need to use a black and white medium, or it may be photocopied, etc.) then consider using a dotplot instead of a barplot, it has a much better data to ink ratio anyways.

If ggplot2 does not have a means to fill barplots with lines/symbols, then that should be considered a feature and evidence of well thought out design rather than any type of lack.


--
--
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/groups/opt_out.
 
 



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

zelfortin

unread,
Aug 1, 2013, 4:09:13 PM8/1/13
to ggp...@googlegroups.com, zelfortin
Thanks a lot for your answer,

finally I decided to dodge my stacked bar plot and use a scale of grey colors. I was afraid that on top of each other they might be hard to discern, especially since some categories have low values. Here's a final result:

Here is the script if anyone needs to do something similar :

Plot1 <- ggplot(Data,aes(factor(Model),fill=factor(Data$New.Curve))) +
  geom_bar(position="dodge") +
  labs(x="Model", y="Count") +
  ggtitle(paste("Best models by year for ", File[e], sep="")) +
  scale_fill_manual(values=Coul) +
  theme_bw() +
  theme(axis.title = element_text(size= 18)) +
  theme(legend.background = element_rect(fill="grey95"))+
  theme(legend.key = element_rect(colour = "grey95",fill="grey95"))+
  theme(legend.key.size = unit(1, "cm"))+
  theme(legend.text = element_text(size = 15))+
  theme(legend.title = element_text(size = 18))+
  theme(axis.text = element_text(size = 14))+
  theme(legend.margin = unit(1,"cm"))+
  theme(axis.title.x = element_text(vjust=-0.5))+
  theme(axis.title.y = element_text( vjust=0, angle=90))+
  theme(plot.margin = unit(c(1,0.2,2,1), "cm"))+
  theme(plot.title = element_text(size=19, face="bold", vjust=2.2))+
  theme(panel.grid = element_blank())+
  labs(fill="Curve")  

Plot1

Cheers

JM

Reply all
Reply to author
Forward
0 new messages