[R] help on bar chart

Greg Snow Greg.Snow at imail.org
Wed Jul 7 19:25:11 CEST 2010


> fortune(197)

If anything, there should be a Law: Thou Shalt Not Even Think Of Producing A
Graph That Looks Like Anything From A Spreadsheet.
   -- Ted Harding (in a discussion about producing graphics)
      R-help (August 2007)

Filling graphics objects with lines dates back to the days when the only way to get decent graphics was with a pen plotter (device that actually had a mechanical arm that would move a pen over paper (or paper under the pen)) which could not easily fill areas (well you could draw the lines really densely, but the usual outcome was that you annoyed other users by taking a long time and using all the ink and often ended up with a hole in the paper instead of a nice fill.

Technology has progressed quite a bit since then, it is best if your graphs reflect that.  Tufte also discusses that such lines actually make graphs harder to read, can actually distort features, and cause other problems.

The fact that lattice graphics do not include a simple way to do this is a feature.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ppcrystal
> Sent: Friday, July 02, 2010 11:47 PM
> To: r-help at r-project.org
> Subject: [R] help on bar chart
> 
> 
> Hey guys,
> 
> This is the bar chart that I am working on:
> 
> library(lattice);
> data <- data.frame(
> 	X1 = c(2300, 1300, 1300, 450),
> 	X2 = c(2110, 2220, 1100, 660),
> 	Y = factor(c("sample1", "sample2", "sample3", "sample4"))
> 	);
> barchart(
> 	Y ~ X1 + X2,
> 	data,
> 	stack = TRUE,
> 	horiz = TRUE,
> 	lwd = 1.5,
> 	xlab = expression(bold("Sample size")),
> 	col = colors()[c(24,1)],
> 	xlim = c(0,5000),
> 	xat = seq(0,5000,1000)
> 	);
> 
> I wanted to make a bar chart that has hatching lines inside the bar:
> with
> sample 2 and 4 having vertical lines and sample 1 and 3 having
> horizontal
> lines, like the following (I kind of photoshopped the image to
> demonstrate
> what I wanted it to look like):
> 
> http://r.789695.n4.nabble.com/file/n2277107/test.png
> 
> Anyone knows how I can add hatching to the bar charts?
> 
> Thanks very much for your time!!!
> --
> View this message in context: http://r.789695.n4.nabble.com/help-on-
> bar-chart-tp2277107p2277107.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list