My first attempt to post the data didn't work. Trying again.
---------------------------------------------------------------
Hello, Thanks to the wonderful R Graphics Cookbook, I was able to get
this graph to make but I still cant get the annotation I want. I just
want to put the numbers of people below each faceted graph. The code
runs without an error message, but no annotations appear. Under each of
the 3 facets I expect "N=nnn" to be printed but I get nothing.
Here is the main data frame:
structure(list(type = c("elem_iva", "elem_iva", "elem_iva", "elem_iva",
"elem_iva", "elem_iva", "elem_iva", "elem_iva", "elem_sva", "elem_sva",
"elem_sva", "elem_sva", "elem_sva", "elem_sva", "elem_sva", "elem_sva",
"elem_sva", "elem_sva", "hs_pt", "hs_pt", "hs_pt", "hs_pt", "hs_pt",
"hs_pt", "hs_pt", "hs_pt", "hs_pt", "hs_pt", "hs_nopt", "hs_nopt",
"hs_nopt", "hs_nopt", "hs_nopt", "hs_nopt", "hs_nopt", "hs_nopt",
"hs_nopt", "hs_nopt"), cat_diff = structure(c(2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L), .Label = c("Lower", "No Change", "Higher"), class = c("ordered",
"factor")), plain_pct = c(0.615384615384615, 0.384615384615385,
0.00763358778625954, 0.816793893129771, 0.175572519083969, 0.092896174863388,
0.896174863387978, 0.0109289617486339, 0.685714285714286, 0.314285714285714,
0.0151515151515152, 0.813131313131313, 0.171717171717172, 0.0839416058394161,
0.908759124087591, 0.0072992700729927, 0, 1, 0.825396825396825,
0.174603174603175, 0.0769230769230769, 0.822485207100592, 0.100591715976331,
0.258928571428571, 0.732142857142857, 0.00892857142857143, 0.5,
0.5, 0.888888888888889, 0.111111111111111, 0.0975609756097561,
0.780487804878049, 0.121951219512195, 0.233333333333333, 0.733333333333333,
0.0333333333333333, 0.333333333333333, 0.666666666666667), plain_summative_cat = c(1,
1, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 1, 1, 2, 2,
2, 3, 3, 3, 4, 4, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4)), class = "data.frame", .Names = c("type",
"cat_diff", "plain_pct", "plain_summative_cat"), row.names = c(NA,
-38L))
This is the annotation data frame:
structure(list(type = c("elem_iva", "elem_iva", "elem_iva", "elem_sva",
"elem_sva", "elem_sva", "elem_sva", "hs_nopt", "hs_nopt", "hs_nopt",
"hs_nopt", "hs_pt", "hs_pt", "hs_pt", "hs_pt"), plain_summative_cat = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("1",
"2", "3", "4"), class = "factor"), N = c(65, 262, 183, 105, 396,
274, 4, 18, 41, 30, 3, 63, 169, 112, 2)), .Names = c("type",
"plain_summative_cat", "N"), row.names = c(NA, -15L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), vars = list(type), drop = TRUE)
And here is my code:
ggplot(all_tab3[all_tab3$type=="elem_iva",], aes(x=cat_diff,
y=plain_pct)) +
geom_bar(stat="identity") +
scale_y_continuous(name="Percentage", labels=percent) +
facet_grid(. ~ plain_summative_cat) +
theme(axis.text.x = element_text(angle=90, hjust=1)) +
geom_text(data=all_ns[all_ns$type=="elem_iva",], x=1, y=-.1,
aes(label=paste("N=", N)))
I'm thinking it must be the x location. In the main graph, the bars are
located by cat_diff, which is coded 0, 1, 2. I thought I'd put the
annotation in the middle of the three bars, so I tried to locate the
text at x=1. Doesn't seem to be working. Can anyone give me a bit of
help?
TIA
--
Stuart Luppescu -=-=- slu <AT> ccsr <DOT> uchicago <DOT> edu
CCSR at U of C ,.;-*^*-;.,
ccsr.uchicago.edu
(^_^)/ 才文と智奈美の父
[Crash programs] fail because they are based on the theory that,
with nine women pregnant, you can get a baby a month.
-- Wernher von Braun