0

I just discovered rCharts. Is it possible to do a density plot? For example with ggplot2 i do:

library(ggplot2)
m <- ggplot(movies, aes(x = rating))
m + geom_density(aes(fill=factor(Drama)), size=2)

Thanks!

Ignacio
  • 7,646
  • 16
  • 60
  • 113

1 Answers1

1

I was able to do this

library(rCharts)
drama = density(movies$rating[movies$Drama==1])
drama = data.frame(drama$x, drama$y)
drama$Var = "Drama"
names(drama) = c("x", "y", "Var")

Nodrama = density(movies$rating[movies$Drama==0])
Nodrama = data.frame(Nodrama$x, Nodrama$y)
Nodrama$Var = "No Drama"
names(Nodrama) = c("x", "y", "Var")
densen1n2 = rbind(drama, Nodrama)
nPlot(x = "x", y = "y", group = "Var", data = densen1n2, type = "lineChart")

Not sure if it is the best way. I'm also not sure how to give a name to the x axis yet

Ignacio
  • 7,646
  • 16
  • 60
  • 113