[R] Panel-specific colours in barchart, lattice package.

From: Rolf Turner <r.turner_at_auckland.ac.nz>
Date: Thu, 12 Jun 2008 15:46:04 +1200

I would like, for possibly invalid reasons, to have the bars of the barchart
in each panel to be the same colour, but with *different* colours from panel
to panel. Can this be done? If so, how?

I've read the help as much as I am capable of, and done an RSiteSearch () without
becoming any wiser.

Here's an example of what I'd like to do:

X <- structure(list(y = c(2.8, 6.7, 12.8, 22.9, 18.4, 16.2, 10.1,

5.6, 4.5, 6.9, 19.8, 25.7, 23.8, 12.9, 5.9, 3, 1, 1, 12.9, 24.2,
24.2, 25, 8.1, 3.2, 1.6, 0.8, 0, 5, 12.5, 25, 17.5, 20, 12.5,
5, 0, 2.5, 25, 33.3, 25, 0, 0, 8.3, 8.3, 0, 0), x = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9"), class = "factor"), f =
structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("a",

"b", "c", "d", "e"), class = "factor")), .Names = c("y", "x",
"f"), row.names = c(NA, -45L), class = "data.frame")

barchart(y ~ x | f, data=X, as.table=TRUE)

EXCEPT that I'd like panel ``a'' to have its bars being, say, solid red, panel ``b'' to have its bars solid blue, panel ``c'' to have its bars solid green, etc.

Can I arrange this? Thanks.

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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. Received on Thu 12 Jun 2008 - 05:15:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Jun 2008 - 06:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive