[R] Help with grouped barplot

Gabor Grothendieck ggrothendieck at gmail.com
Tue Nov 23 21:00:50 CET 2010


On Tue, Nov 23, 2010 at 2:49 PM, Art Burke
<Art.Burke at educationnorthwest.org> wrote:
> Given the data structure below, how can I create a bar plot for the values of disc for each area grouped by year?
>
> bar <-structure(list(year = c(2003, 2003, 2003, 2003, 2003, 2003, 2003,
> 2007, 2007, 2007, 2007, 2007, 2007, 2007), area = structure(c(6L,
> 4L, 1L, 2L, 3L, 5L, 7L, 6L, 4L, 1L, 2L, 3L, 5L, 7L), .Label = c("AK",
> "ID", "MT", "NW", "OR", "US", "WA"), class = "factor"), disc = c(55.8,
> 62.6, 54.3, 56.9, 52.8, 66.7, 64.8, 59.5, 64.8, 65.8, 61.4, 60.6,
> 66.3, 65.5)), .Names = c("year", "area", "disc"), class = "data.frame", row.names = c(NA,
> 14L))
>

Try this:

library(lattice)
barchart(disc ~ year | area, horiz = FALSE,  transform(bar, year =
factor(year)))

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list