[R] Panel-specific colours in barchart, lattice package.
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jun 12 06:05:03 CEST 2008
Try this:
barchart(y ~ x | f, data=X, as.table=TRUE,
panel = function(...) panel.barchart(..., col = panel.number()))
On Wed, Jun 11, 2008 at 11:46 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>
> 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.
>
More information about the R-help
mailing list