Loading Libraries
library(knitr)
library(printr)
library(rCharts)
head(MASS::survey)
| Sex | Wr.Hnd | NW.Hnd | W.Hnd | Fold | Pulse | Clap | Exer | Smoke | Height | M.I | Age |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Female | 18.5 | 18.0 | Right | R on L | 92 | Left | Some | Never | 173.00 | Metric | 18.250 |
| Male | 19.5 | 20.5 | Left | R on L | 104 | Left | None | Regul | 177.80 | Imperial | 17.583 |
| Male | 18.0 | 13.3 | Right | L on R | 87 | Neither | None | Occas | NA | NA | 16.917 |
| Male | 18.8 | 18.9 | Right | R on L | NA | Neither | None | Never | 160.00 | Metric | 20.333 |
| Male | 20.0 | 20.0 | Right | Neither | 35 | Right | Some | Never | 165.00 | Metric | 23.667 |
| Female | 18.0 | 17.7 | Right | L on R | 64 | Right | Some | Never | 172.72 | Imperial | 21.000 |
\(\\\)
library(MASS)
h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = survey,
type = c("line", "bubble", "scatter"),
group = "Clap",
size = "Age")
h1$show('inline', include_assets = TRUE)
\(\\\)
h2 <- hPlot(Pulse ~ Height, data = survey,
type = "scatter", group = "Exer")
h2$show('inline', include_assets = TRUE)
\(\\\)
h3 <- hPlot(Pulse ~ Height, data = survey,
type = "bubble",
group = "Exer",
title = "Pulse vs. Heigh chart ",
subtitle = "bubble chart",
size = "Age",
group = "Exer")
h3$show('inline', include_assets = TRUE)
\(\\\)
x <- data.frame(key = c("a", "b", "c"), value = c(1, 2, 3))
h4 <- hPlot(x = "key", y = "value", data = x, type = "pie")
h4$show('inline', include_assets = TRUE)
\(\\\)
h5<- hPlot(Pulse ~ Height, data = survey,
type = 'scatter',
group = 'Sex',
radius = 6,
group.na = "Not Available")
h5$colors('rgba(223, 83, 83, .5)',
'rgba(119, 152, 191, .5)',
'rgba(60, 179, 113, .5)')
h5$legend(align = 'right', verticalAlign = 'top', layout = 'vertical')
h5$plotOptions(scatter = list(marker = list(symbol = 'circle')))
h5$tooltip(formatter = "#! function() { return this.x + ', ' + this.y; } !#")
h5$show('inline', include_assets = TRUE)
\(\\\)
Data for plot:
library(plyr)
data <- count(survey, c('Sex', 'Exer'))
data
| Sex | Exer | freq |
|---|---|---|
| Female | Freq | 49 |
| Female | None | 11 |
| Female | Some | 58 |
| Male | Freq | 65 |
| Male | None | 13 |
| Male | Some | 40 |
| NA | Freq | 1 |
Plot:
h6 <- hPlot(freq ~ Exer, data = data,
type = c('column', 'line'),
group = 'Sex',
radius = 6)
h6$show('inline', include_assets = TRUE)
\(\\\)
Data for plot:
library(plyr)
data <- count(survey, c('Sex', 'Exer'))
data
| Sex | Exer | freq |
|---|---|---|
| Female | Freq | 49 |
| Female | None | 11 |
| Female | Some | 58 |
| Male | Freq | 65 |
| Male | None | 13 |
| Male | Some | 40 |
| NA | Freq | 1 |
Plot:
h7 <- hPlot(freq ~ Exer, data = data,
type = 'bar',
group = 'Sex',
group.na = 'NA\'s')
h7$show('inline', include_assets = TRUE)
\(\\\)
h8 <- hPlot(freq ~ Exer, data = data,
type = 'column',
group = 'Sex',
group.na = 'NA\'s')
h8$plotOptions(column = list(dataLabels =
list(enabled = T, rotation = -90, align = 'right',
color = '#FFFFFF', x = 4, y = 10,
style = list(fontSize = '13px',
fontFamily = 'Verdana, sans-serif'))))
h8$xAxis(labels = list(rotation = -45,
align = 'right',
style = list(fontSize = '13px',
fontFamily = 'Verdana, sans-serif')),
replace = F)
h8$show('inline', include_assets = TRUE)
\(\\\)
h9 <- hPlot(freq ~ Exer, data = data,
type = 'bar',
group = 'Sex',
group.na = 'NA\'s')
h9$plotOptions(bar = list(cursor = 'pointer',
point = list(events = list(click = "#! function() { alert ('Category: '+ this.category +', value: '+ this.y); } !#"))))
h9$show('inline', include_assets = TRUE)
\(\\\)
h10 <- Highcharts$new()
h10$series(data = list(
list(y = 8, url = "https://github.com/metagraf/rHighcharts", color = "lightblue"),
list(y = 14, url = "https://github.com/metagraf/rVega", color = "lightpink"),
list(y = 71, url = "https://github.com/ramnathv/rCharts", color = "lightgreen")),
type = "column", name = "Number of Stars")
h10$plotOptions(column = list(cursor = 'pointer',
point = list(events = list(click = "#! function() { location.href = this.options.url; } !#"))))
h10$xAxis(categories = c("rHighcharts", "rVega", "rCharts"),
title = list(text = ""))
h10$yAxis(title = list(text = ""))
h10$legend(enabled = F)
h10$show('inline', include_assets = TRUE)