r - Faceting bars in ggplot2 -
i have problem: want build stacked bar plot faceting capabilities, can compare distribution of frequencies 5 common categories, within 2 different objects, separated according 3 groups. have 6 objects, 5 categories , 3 groups. problem each group has 2 different , exclusive objects plot, far can produce plot in 6 objects plotted across 3 groups. not optimal, since each group have 4 objects no data.
is possible plot 2 objects each group faceting capabilities?
edited
this data:
structure(list(face = structure(c(1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 3l, 3l, 3l, 3l, 3l, 4l, 4l, 4l, 4l, 4l, 5l, 5l, 5l, 5l, 5l, 6l, 6l, 6l, 6l, 6l), .label = c("lgh002", "lgh003", "lgm009", "scm018", "vah022", "vam028"), class = "factor"), race = structure(c(1l, 2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l), .label = c("1. amerindian", "2. white", "3. mestizo", "4. other races", "5. cannot tell"), class = "factor"), count = c(19l, 0l, 13l, 8l, 0l, 2l, 7l, 23l, 6l, 2l, 1l, 1l, 29l, 6l, 3l, 29l, 0l, 11l, 0l, 0l, 0l, 38l, 1l, 0l, 1l, 0l, 30l, 9l, 0l, 1l), density = c(0.475, 0, 0.325, 0.2, 0, 0.05, 0.175, 0.575, 0.15, 0.05, 0.025, 0.025, 0.725, 0.15, 0.075, 0.725, 0, 0.275, 0, 0, 0, 0.95, 0.025, 0, 0.025, 0, 0.75, 0.225, 0, 0.025), school = structure(c(1l, 1l, 1l, 1l, 1l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l), .label = c("municipal", "private fee-paying", "private-voucher"), class = "factor")), .names =c("face", "race", "count", "density", "school"), class = "data.frame", row.names = c(na, -30l))
this code i'm using build plot:
p <- ggplot(data = races.df, aes(x = face, y = density, fill = race)) + geom_bar(stat="identity") + scale_y_continuous(labels=percent) p + facet_grid(school ~ ., scales="free") + coord_flip()
as can imagine, want see x-values "scm018" , "lgh002" in "municipal"; "lgm009" , "lgh003" in "private-voucher"; , "vah022" , "vam028" in "private fee-paying" (only 2 objects per group). possible? help?
all best,
mauricio.
Comments
Post a Comment