Skip to Content

aggregate/sum with ggplot

Is there a way to sum data with ggplot2 ?

I want to do a bubble map with the size depending of the sum of z.

Currently I'm doing something like

dd <- ddply(d, .(x,y), transform, z=sum(z))
qplot(x,y, data=dd, size=z)

But I feel I'm writing the same thing twice, I would like to be able to write something

qplot(x,y, data=dd, size=sum(z))

I had a look at stat_sum and stat_summmary but I'm not sure they are appropriate either.

Is it possible to it with ggplot2 ? If not, what would be best way to write those 2 lines.