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 foundggplot(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?
dat2
created? – akruntidyr
library. Create thedat
dataframe:dat <- data.frame(A = rep(1, 3), B = rep(2, 3), C = rep(3, 3))
. You are referencingdat2
in your ggplot calls. What isdat2
? – timtricedat[, sum(y)]
will not work because there is no 'y' column and it is not a data.table – akrun