Hi Brandon,
Tweaking with the heights isn't ideal, since if my labels change for
example, i'll have to re-tweak the heights all over again. Might be a
good last resort.
Here's some reproducible code that leads to the plot seen here:
http://i.imgur.com/okbwX55.png
Any thoughts about how to get the tick labels aligned?
thanks.
groups = c("grp1","grp2","grp3")
my_df = data.frame(group = sample(groups,100,replace=T), surv1 =
sample(c(1,0),100,replace=T), surv2 = sample(c(1,0),100,replace=T))
my_df_summ =
ddply(my_df, "group", summarize, surv_rate1 = mean(surv1), num_surv1
= sum(surv1),
surv_rate2 = mean(surv2), num_surv2 =
sum(surv2),
n = length(surv1))
require(binom)
attach(my_df_summ)
limits1 = binom.confint(num_surv1, n, method="exact")
limits2 = binom.confint(num_surv2, n, method="exact")
detach(my_df_summ)
ggsurv1 = ggplot(my_df_summ, aes(x=group, y=surv_rate1)) +
geom_bar(stat="identity") +
geom_errorbar(aes(ymax = limits1$upper, ymin = limits1$lower),
position = "dodge", width = 0.25, col="darkgrey")
ggsurv2 = ggplot(my_df_summ, aes(x=group, y=surv_rate2)) +
geom_bar(stat="identity") +
geom_errorbar(aes(ymax = limits2$upper, ymin = limits2$lower),
position = "dodge", width = 0.25, col="darkgrey")
plot_grobs = ggplot_gtable(ggplot_build(ggsurv1 + ylab("")))$grobs
require(gridExtra)
grid.arrange(ggsurv1 + scale_x_discrete(labels="") + xlab("") + ylab(""),
ggsurv2+ scale_x_discrete(labels="") + xlab("") + ylab(""),
plot_grobs[[5]], ncol=1,
left = "Proportion alive")