If you do not want to calculate a new data frame before plotting, you can use stat_summaryin ggplot2. For example, if your dataset looks like this:
R> df <- data.frame(Genre=c("Comedy","Drama","Action","Comedy","Drama"),
R+ Amount=c(10,30,40,10,20))
R> df
Genre Amount
1 Comedy 10
2 Drama 30
3 Action 40
4 Comedy 10
5 Drama 20
You can use either qplotwith an argument stat="summary":
R> qplot(Genre, Amount, data=df, stat="summary", fun.y="sum")
Or add stat_summaryto the base chart ggplot:
R> ggplot(df, aes(x=Genre, y=Amount)) + stat_summary(fun.y="sum", geom="point")
source
share