Loading Libraries

library(knitr)
library(printr)
library(rCharts)

Dataset used in this document

mtcars

head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

HairEyeColor

hair_eye = as.data.frame(HairEyeColor)
hair_eye
Hair Eye Sex Freq
Black Brown Male 32
Brown Brown Male 53
Red Brown Male 10
Blond Brown Male 3
Black Blue Male 11
Brown Blue Male 50
Red Blue Male 10
Blond Blue Male 30
Black Hazel Male 10
Brown Hazel Male 25
Red Hazel Male 7
Blond Hazel Male 5
Black Green Male 3
Brown Green Male 15
Red Green Male 7
Blond Green Male 8
Black Brown Female 36
Brown Brown Female 66
Red Brown Female 16
Blond Brown Female 4
Black Blue Female 9
Brown Blue Female 34
Red Blue Female 7
Blond Blue Female 64
Black Hazel Female 5
Brown Hazel Female 29
Red Hazel Female 7
Blond Hazel Female 5
Black Green Female 2
Brown Green Female 14
Red Green Female 7
Blond Green Female 8

economics

library(ggplot2)
head(economics)
date pce pop psavert uempmed unemploy
1967-06-30 507.8 198712 9.8 4.5 2944
1967-07-31 510.9 198911 9.8 4.7 2945
1967-08-31 516.7 199113 9.0 4.6 2958
1967-09-30 513.3 199311 9.8 4.9 3143
1967-10-31 518.5 199498 9.7 4.7 3066
1967-11-30 526.2 199657 9.4 4.8 3018

Plot 1: Scatter Chart

p1 <- nPlot(mpg ~ wt, 
            group = 'cyl', 
            data = mtcars, 
            type = 'scatterChart')

p1$xAxis(axisLabel = 'Weight')

p1$show('inline', include_assets = TRUE)

\(\\\)

Plot 2: MultiBar Chart

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$show('inline', include_assets = TRUE)