Reputation: 109
I am trying to find straightforward methods to sum the data by various factors in ggplot.
Sample data (dat):
A B C
1 2 3
1 2 3
1 2 3
library(ggplot2)
library(reshape)
dat1 <- gather(dat) #convert into long form with 'key' and 'value'
I have tried the following methods:
qplot(x, y, data=dat1[, sum(y)],by = "key,value", size=V1)
Error in [.data.frame
(dat1, , sum(y)) : object 'y' not found
ggplot(data = dat1, aes(x = key, y = value)) + stat_summary(fun.y = sum, colour = "red", size = 1) Error in eval(expr, envir, enclos) : object 'key' not found
Can anyone recommend where I may be going wrong and alternatives to the same?
Upvotes: 1
Views: 10498
Reputation: 887811
We can specify the geom
library(ggplot2)
ggplot(data = dat1, aes(x = key, y = value)) +
stat_summary(fun.y = sum, geom="point", colour = "red", size = 1)
Upvotes: 4