Skip to content

Commit e5b3950

Browse files
committed
Added an rCharts lecture start, still working on it
1 parent 9868adb commit e5b3950

6 files changed

Lines changed: 964 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!doctype HTML>
2+
<meta charset = 'utf-8'>
3+
<html>
4+
<head>
5+
6+
<script src='http://ramnathv.github.io/rCharts/libraries/widgets/polycharts/js/polychart2.standalone.js' type='text/javascript'></script>
7+
8+
<style>
9+
.rChart {
10+
display: block;
11+
margin-left: auto;
12+
margin-right: auto;
13+
width: 800px;
14+
height: 400px;
15+
}
16+
</style>
17+
18+
</head>
19+
<body>
20+
<div id='chart16c56388ccbc' class='rChart polycharts'></div>
21+
22+
<script type='text/javascript'>
23+
var chartParams = {
24+
"dom": "chart16c56388ccbc",
25+
"width": 800,
26+
"height": 400,
27+
"layers": [
28+
{
29+
"x": "SepalWidth",
30+
"y": "SepalLength",
31+
"data": {
32+
"SepalLength": [ 5.1, 4.9, 4.7, 4.6, 5, 5.4, 4.6, 5, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1, 5.4, 5.1, 4.6, 5.1, 4.8, 5, 5, 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5, 5.5, 4.9, 4.4, 5.1, 5, 4.5, 4.4, 5, 5.1, 4.8, 5.1, 4.6, 5.3, 5, 7, 6.4, 6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5, 5.9, 6, 6.1, 5.6, 6.7, 5.6, 5.8, 6.2, 5.6, 5.9, 6.1, 6.3, 6.1, 6.4, 6.6, 6.8, 6.7, 6, 5.7, 5.5, 5.5, 5.8, 6, 5.4, 6, 6.7, 6.3, 5.6, 5.5, 5.5, 6.1, 5.8, 5, 5.6, 5.7, 5.7, 6.2, 5.1, 5.7, 6.3, 5.8, 7.1, 6.3, 6.5, 7.6, 4.9, 7.3, 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1.7, 1.5, 1, 1.1, 1, 1.2, 1.6, 1.5, 1.6, 1.5, 1.3, 1.3, 1.3, 1.2, 1.4, 1.2, 1, 1.3, 1.2, 1.3, 1.3, 1.1, 1.3, 2.5, 1.9, 2.1, 1.8, 2.2, 2.1, 1.7, 1.8, 1.8, 2.5, 2, 1.9, 2.1, 2, 2.4, 2.3, 1.8, 2.2, 2.3, 1.5, 2.3, 2, 2, 1.8, 2.1, 1.8, 1.8, 1.8, 2.1, 1.6, 1.9, 2, 2.2, 1.5, 1.4, 2.3, 2.4, 1.8, 1.8, 2.1, 2.4, 2.3, 1.9, 2.3, 2.5, 2.3, 1.9, 2, 2.3, 1.8 ],
36+
"Species": [ "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "setosa", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "versicolor", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica", "virginica" ]
37+
},
38+
"facet": "Species",
39+
"color": "Species",
40+
"type": "point"
41+
}
42+
],
43+
"facet": {
44+
"type": "wrap",
45+
"var": "Species"
46+
},
47+
"guides": [],
48+
"coord": [],
49+
"id": "chart16c56388ccbc"
50+
}
51+
_.each(chartParams.layers, function(el){
52+
el.data = polyjs.data(el.data)
53+
})
54+
var graph_chart16c56388ccbc = polyjs.chart(chartParams);
55+
</script>
56+
57+
</body>
58+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!doctype HTML>
2+
<meta charset = 'utf-8'>
3+
<html>
4+
<head>
5+
6+
<script src='http://ramnathv.github.io/rCharts/libraries/widgets/polycharts/js/polychart2.standalone.js' type='text/javascript'></script>
7+
8+
<style>
9+
.rChart {
10+
display: block;
11+
margin-left: auto;
12+
margin-right: auto;
13+
width: 800px;
14+
height: 400px;
15+
}
16+
</style>
17+
18+
</head>
19+
<body>
20+
<div id='chart16c57cd13d81' class='rChart polycharts'></div>
21+
22+
<script type='text/javascript'>
23+
var chartParams = {
24+
"dom": "chart16c57cd13d81",
25+
"width": 800,
26+
"height": 400,
27+
"layers": [
28+
{
29+
"x": "Hair",
30+
"y": "Freq",
31+
"data": {
32+
"Hair": [ "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond" ],
33+
"Eye": [ "Brown", "Brown", "Brown", "Brown", "Blue", "Blue", "Blue", "Blue", "Hazel", "Hazel", "Hazel", "Hazel", "Green", "Green", "Green", "Green", "Brown", "Brown", "Brown", "Brown", "Blue", "Blue", "Blue", "Blue", "Hazel", "Hazel", "Hazel", "Hazel", "Green", "Green", "Green", "Green" ],
34+
"Sex": [ "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female" ],
35+
"Freq": [ 32, 53, 10, 3, 11, 50, 10, 30, 10, 25, 7, 5, 3, 15, 7, 8, 36, 66, 16, 4, 9, 34, 7, 64, 5, 29, 7, 5, 2, 14, 7, 8 ]
36+
},
37+
"facet": "Eye",
38+
"color": "Eye",
39+
"type": "bar"
40+
}
41+
],
42+
"facet": {
43+
"type": "wrap",
44+
"var": "Eye"
45+
},
46+
"guides": [],
47+
"coord": [],
48+
"id": "chart16c57cd13d81"
49+
}
50+
_.each(chartParams.layers, function(el){
51+
el.data = polyjs.data(el.data)
52+
})
53+
var graph_chart16c57cd13d81 = polyjs.chart(chartParams);
54+
</script>
55+
56+
</body>
57+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!doctype HTML>
2+
<meta charset = 'utf-8'>
3+
<html>
4+
<head>
5+
6+
<script src='http://ramnathv.github.io/rCharts/libraries/widgets/polycharts/js/polychart2.standalone.js' type='text/javascript'></script>
7+
8+
<style>
9+
.rChart {
10+
display: block;
11+
margin-left: auto;
12+
margin-right: auto;
13+
width: 800px;
14+
height: 400px;
15+
}
16+
</style>
17+
18+
</head>
19+
<body>
20+
<div id='chart16c54957c2a4' class='rChart polycharts'></div>
21+
22+
<script type='text/javascript'>
23+
var chartParams = {
24+
"dom": "chart16c54957c2a4",
25+
"width": 800,
26+
"height": 400,
27+
"layers": [
28+
{
29+
"x": "Hair",
30+
"y": "Freq",
31+
"data": {
32+
"Hair": [ "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond", "Black", "Brown", "Red", "Blond" ],
33+
"Eye": [ "Brown", "Brown", "Brown", "Brown", "Blue", "Blue", "Blue", "Blue", "Hazel", "Hazel", "Hazel", "Hazel", "Green", "Green", "Green", "Green", "Brown", "Brown", "Brown", "Brown", "Blue", "Blue", "Blue", "Blue", "Hazel", "Hazel", "Hazel", "Hazel", "Green", "Green", "Green", "Green" ],
34+
"Sex": [ "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female", "Female" ],
35+
"Freq": [ 32, 53, 10, 3, 11, 50, 10, 30, 10, 25, 7, 5, 3, 15, 7, 8, 36, 66, 16, 4, 9, 34, 7, 64, 5, 29, 7, 5, 2, 14, 7, 8 ]
36+
},
37+
"facet": "Eye",
38+
"color": "Eye",
39+
"type": "bar"
40+
}
41+
],
42+
"facet": {
43+
"type": "wrap",
44+
"var": "Eye"
45+
},
46+
"guides": [],
47+
"coord": [],
48+
"id": "chart16c54957c2a4"
49+
}
50+
_.each(chartParams.layers, function(el){
51+
el.data = polyjs.data(el.data)
52+
})
53+
var graph_chart16c54957c2a4 = polyjs.chart(chartParams);
54+
</script>
55+
56+
</body>
57+
</html>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title : rCharts
3+
subtitle : Building Data Products
4+
author : Brian Caffo, Jeff Leek, Roger Peng
5+
job : Johns Hopkins Bloomberg School of Public Health
6+
logo : bloomberg_shield.png
7+
framework : io2012
8+
highlighter : highlight.js
9+
hitheme : tomorrow
10+
url:
11+
lib: ../../librariesNew #Remove new if using old slidify
12+
assets: ../../assets
13+
widgets : [mathjax, quiz, bootstrap]
14+
mode : selfcontained # {standalone, draft}
15+
ext_widgets : {rCharts: ["libraries/nvd3"]}
16+
---
17+
```{r setup, cache = F, echo = F, message = F, warning = F, tidy = F, results='hide'}
18+
# make this an external chunk that can be included in any file
19+
library(knitr)
20+
options(width = 100)
21+
opts_chunk$set(message = F, error = F, warning = F, comment = NA, fig.align = 'center', dpi = 100, tidy = F, cache.path = '.cache/', fig.path = 'fig/')
22+
23+
options(xtable.type = 'html')
24+
knit_hooks$set(inline = function(x) {
25+
if(is.numeric(x)) {
26+
round(x, getOption('digits'))
27+
} else {
28+
paste(as.character(x), collapse = ', ')
29+
}
30+
})
31+
knit_hooks$set(plot = knitr:::hook_plot_html)
32+
runif(1)
33+
```
34+
35+
## rCharts
36+
- rCharts is a way to create interactive javascript visualizations using R
37+
- So
38+
- You don't have to learn complex tools, like D3
39+
- You simply work in R learning a minimal amount of new syntaxt
40+
- rCharts was written by Ramnath Vaidyanathan (friend of the Data Science Series), who also wrote slidify, the framework we use for all of the lectures in the class
41+
- This lecture is basically going through
42+
(http://ramnathv.github.io/rCharts/)
43+
44+
---
45+
## Example
46+
```
47+
require(rCharts)
48+
haireye = as.data.frame(HairEyeColor)
49+
nPlot(Freq ~ Hair, group = 'Eye', type = 'multiBarChart',
50+
data = subset(haireye, Sex == 'Male')
51+
)
52+
```
53+
54+
---
55+
## Holy eye candy Batman!
56+
```{r, echo = FALSE, results = 'hide'}
57+
require(rCharts)
58+
```
59+
```{r echo = FALSE, results = 'asis'}
60+
haireye = as.data.frame(HairEyeColor)
61+
n1 <- nPlot(Freq ~ Hair, group = 'Eye', type = 'multiBarChart',
62+
data = subset(haireye, Sex == 'Male')
63+
)
64+
n1$print('chart1')
65+
```
66+
67+
---
68+
## Slidify interactive
69+
- The above was an example of embedding an rChart in a slidify document
70+
- In the YAML
71+
```yaml ext_widgets : {rCharts: ["libraries/nvd3"]}```
72+
73+
---
74+
## Deconstructing another example
75+
```
76+
## Example 1 Facetted Scatterplot
77+
names(iris) = gsub("\\.", "", names(iris))
78+
rPlot(SepalLength ~ SepalWidth | Species, data = iris, color = 'Species', type = 'point')
79+
```
80+
81+
82+
---
83+
## When run
84+
```{r echo = FALSE, results = 'asis'}
85+
## Example 1 Facetted Scatterplot
86+
names(iris) = gsub("\\.", "", names(iris))
87+
rPlot(SepalLength ~ SepalWidth | Species, data = iris, color = 'Species', type = 'point')
88+
```
89+
90+
---
91+
## Example 2 Facetted Barplot
92+
```
93+
hair_eye = as.data.frame(HairEyeColor)
94+
rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar')
95+
```
96+
97+
---
98+
## Example 2 Facetted Barplot, when run
99+
```{r echo = FALSE, results = 'asis'}
100+
hair_eye = as.data.frame(HairEyeColor)
101+
rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar')
102+
```
103+
104+

0 commit comments

Comments
 (0)