White lines in between different levels of stacked bar chart

1,771 views
Skip to first unread message

Kim

unread,
Apr 22, 2012, 6:28:38 PM4/22/12
to ggp...@googlegroups.com
Dear Group,

My stacked bar charts have an appearance issue that I am hoping you can help me with.  Here is some sample code:
#Test dataset
value = c(1,2,3,1,2,3,1,2,3)
participation = c(1,1,1,2,2,2,3,3,3)
ds=as.data.frame(cbind(value,participation))
ggplot(ds,aes(factor(value), fill=factor(participation))) + geom_bar()

which produces the attached file.  See the white line between the green and pink colours?  It isn't there between the blue and green, which is my preference.  Is there any way to get rid of this white line?

Thanks so much for your help.
Kim

test.png

Joran

unread,
Apr 22, 2012, 7:29:57 PM4/22/12
to ggp...@googlegroups.com
I don't see the white lines when I run that code on my computer (either in a Quartz() device or saved as a png). It might help folks figure this out if you provide the output from sessionInfo() so that we know what version of R/ggplot you're using and what OS you're on.

Stuart Luppescu

unread,
Apr 22, 2012, 7:39:49 PM4/22/12
to ggp...@googlegroups.com
I think it's a quirk of the graphics device. I ran the same code and
saved it to a pdf file and found no white line. In your png plot, you
may be able to make it look better by experimenting with different
resolutions. I have used res=200 with good effect.

On a semi-related topic, graphics in the New York Times, which, if I'm
not mistaken, uses R and ggplot for a lot of their graphs, looks like
they use a white background and white grid lines that appear on top of
the graphics elements. Here's an example (not the best, but it was all I
could find in 10 minutes of searching):
http://www.nytimes.com/interactive/2012/04/04/business/the-cost-of-higher-fuel-economy.html

Anyone know how to do this in ggplot?

--
Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
University of Chicago -=- CCSR
鐃緒申文鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 -=- Kernel 3.2.1-gentoo-r2
Kenn Konstabel: [...] There's more to this trend: SPSS and Statistica
now advertise "R language support": [...] Charles C. Berry: If you can't
beat R, join R. Marc Schwartz: "Resistance is futile. You will be
assimilated." -- Kenn Konstabel, Charles C. Berry, and Marc Schwartz
(about the RPro release from REvolution) R-help (August 2008)

Kim

unread,
Apr 22, 2012, 8:55:09 PM4/22/12
to ggp...@googlegroups.com
Dear Joran and Stuart,

Thanks for your help.  Setting it to a higher resolution worked like a charm!

And if it is of interest to anyone, I've included the output from sessionInfo below.

Best wishes!
Kim

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                    LC_TIME=English_Canada.1252   

attached base packages:
[1] stats     graphics  grDevices utils     datasets  grid      methods   base    

other attached packages:
[1] reshape_0.8.4 plyr_1.6      proto_0.3-9.2

loaded via a namespace (and not attached):
[1] ggplot2_0.8.9

Joran

unread,
Apr 23, 2012, 9:58:23 AM4/23/12
to ggp...@googlegroups.com
Glad it worked out. Just so you know, you're using a fairly old version of R and the previous version of ggplot2. It will probably be a good idea to upgrade to the latest versions.
Reply all
Reply to author
Forward
0 new messages