How to group data using GoogleVis in R -
i have data frame:
df <- data.frame(country=c("us", "gb", "br", "us"), val1=c(1, 3, 4, 6), val2=c(23, 12, 32, 17))
when plot bar chart using googlevis
, gives me barlines each country (us twice).
bar1 <- gvisbarchart(df, xvar="country", yvar=c("val1", "val2")) plot(bar1)
what want group sum of val1
, val2
on graph.
try aggregating data first.
library(googlevis) df.summary <- aggregate(cbind(val1, val2) ~ country, data=df, fun = sum) df.summary ## country val1 val2 ## 1 br 4 32 ## 2 gb 3 12 ## 3 7 40 bar1 <- gvisbarchart(df, xvar="country", yvar=c("val1", "val2")) plot(bar1)
Comments
Post a Comment