1
votes

Just wondering if it is possible to manipulable the y-axis of ggplot with geom_bar

for example:

library(plyr)
df1 <- data.frame(a=c(5,5,10,10,10))
df2 <- ddply(df1,.(a),sum)
ggplot(df2,aes(a,V1)) + geom_bar(stat="identity")

instead of aggregating df1, would it be possible to produce that plot directly in ggplot?

1
I don't really know what to manipulable the y-axis of ggplot has to do with this code. - David Robinson
David, what I meant is to apply a function that computes the y-axis from values that are grouped and represented on the x-axis. like the basic geom_bar counts the values, I wanted other ways of manipulating the data. - jamborta

1 Answers

5
votes

You can do this using stat_summary:

ggplot(df1, aes(a, a)) +
  stat_summary(fun.y=sum, geom="bar")