Create¶
rCharts uses a formula interface to specify plots, just like the lattice package. Here are a few examples you can try out in your R console.
Note
Every example comes with an edit button that allows you to experiment with the code online. The online playground was built using OpenCPU
First let us load the rCharts package
library(rCharts)
NVD3¶
hair_eye = as.data.frame(HairEyeColor)
p2 <- nPlot(Freq ~ Hair, group = 'Eye',
data = subset(hair_eye, Sex == "Female"),
type = 'multiBarChart'
)
p2$chart(color = c('brown', 'blue', '#594c26', 'green'))
p2
Morris¶
data(economics, package = "ggplot2")
econ <- transform(economics, date = as.character(date))
m1 <- mPlot(x = "date", y = c("psavert", "uempmed"), type = "Line", data = econ)
m1$set(pointSize = 0, lineWidth = 1)
m1
Highcharts¶
h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd",
data = MASS::survey,
type = c("line", "bubble", "scatter"),
group = "Clap",
size = "Age"
)
h1
Rickshaw¶
usp = reshape2::melt(USPersonalExpenditure)
usp$Var2 <- as.numeric(as.POSIXct(paste0(usp$Var2, "-01-01")))
p4 <- Rickshaw$new()
p4$layer(value ~ Var2, group = "Var1", data = usp, type = "area")
p4$set(slider = TRUE)
p4