tags:

views:

263

answers:

1

I have a nearly-boxplot like jitter-plot:

dt <- rbind(se,cb,cb.se)
qplot(ds, size, data=dt, geom="jitter", colour=root, facets = test ~ .)

plot

I'd love to put a summary label for each group in the middle of the plot - for example the size totals here:

 aggregate(list(size=dt$size), list(dt$ds, dt$test), sum)

   Group.1  Group.2   size
1     b217       se   9847
2      c10       se  97296
3     c613       se  21633
4       c7       se 207540
...

I've tried using + geom_text(aes(x=ds, y=128, label=sum(size)), size=2) to add labels, but I get the same label on each position - how can I get the sum of just that section of data?

Edit: Here's where I'm at now - maybe I'm just going in the wrong direction

data <- rbind(se,cb,cb.se)
labels <-ddply(data, c("ds", "test"), function(df) sum(df$size))
ggplot(data=data, aes(x=ds)) +
  geom_jitter(aes(y=size, colour=root)) +
  geom_text(data=labels, aes(x=ds, y=600, label=V1), size=3) +
  facet_wrap(test ~ .)

This code doesn't work - I get an undefined columns selected error... somewhere. Maybe it's because of the multiple data= sections?

A: 

Take a look here. It may be helpful Adding direct labels to ggplot2 and lattice plots

gd047
directlabels doesn't solve my problem, it doesn't position well on jitter plots, and it wants to use my legend labels to label the chart instead of provided labels.
Thelema