I have the following table in R (inspired by a cran help datasheet) :
> dfx <- data.frame(
+ group = c(rep('A', 108), rep('B', 115), rep('C', 106)),
+ sex = sample(c("M", "F","U"), size = 329, replace = TRUE),
+ age = runif(n = 329, min = 18, max = 54)
+ )
> head(dfx)
group sex age
1 A U 47.00788
2 A M 32.40236
3 A M 21.95732
4 A F 19.82798
5 A F 30.70890
6 A M 30.00830
I am interested in plotting the percentages of males (M), females (F) and "unknown"(U) in each group using barcharts, including error bars. To do this graph, i plan to use the panel.ci/prepanel.ci commands.
I can easily build a proportion table for each group using the prop.table command :
> with(dfx, prop.table(table(group,sex), margin=1)*100)
sex
group F M U
A 29.62963 28.70370 41.66667
B 35.65217 35.65217 28.69565
C 37.73585 33.01887 29.24528
But now, i would like to build a similar table with error bars, and use these two tables to make a barchart.
If possible, i would like to use the ddply
command, that i use for similar purposes (except that it was nor percentages but means).