-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgoogleVis.Rmd
98 lines (78 loc) · 2.49 KB
/
googleVis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Markdown example with knitr and googleVis
===========================================
This is a little Markdown example file. It uses googleVis package with knitr and markdown to produce interactive plots from **Google Visualization API**.
In this case change the behaviour of plot.gvis, so that it presents only
the code for the chart rather than making a full web page.
```{r setOptions, message=FALSE}
library(googleVis)
op <- options(gvis.plot.tag='chart')
```
The following plot statements will automatically return the HTML
required for the 'knitted' output.
## Pie chart
example pie charts
Let's take a look at the data:
```{r}
head(CityPopularity)
```
Now plot the pie chart
```{r gvisPieChart, results='asis'}
Pie <- gvisPieChart(CityPopularity,
options=list(width=400, height=200))
plot(Pie)
```
## Place two charts next to each other
Example of a gvisGeoChart with gvisTable
Let's have a look at the data first
```{r}
head(Exports)
```
```{r gvisMergeExample, results='asis'}
Geo <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit',
options=list(height=300, width=350))
Tbl <- gvisTable(Exports, options=list(height=300, width=200))
plot(gvisMerge(Geo, Tbl, horizontal=TRUE))
``````
## Scatter Plot
Scatter plot example with googleVis
```{r}
head(women)
```
This time we will be able to edit the plot since we set `gvis.editor` argument.
```{r ScatterPlotExample, results='asis', tidy=TRUE}
Scatter1 <- gvisScatterChart(women,
options=list(
gvis.editor="edit",vAxis="{title:'weight (lbs)'}",
hAxis="{title:'height (in)'}"))
plot(Scatter1)
```
## Intensity Map
```{r}
df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
head(df)
```
```{r IntensityExample, results='asis', tidy=TRUE}
Intensity1 <- gvisIntensityMap(df, locationvar="country", numvar=c("val1", "val2"))
plot(Intensity1)
```
## Combo chart
```{r ComboExample, results='asis', tidy=FALSE}
## Add the mean
CityPopularity$Mean=mean(CityPopularity$Popularity)
CC <- gvisComboChart(CityPopularity, xvar='City',
yvar=c('Mean', 'Popularity'),
options=list(seriesType='bars',
width=450, height=300,
title='City Popularity',
series='{0: {type:\"line\"}}'))
plot(CC)
```
```{r resetOptions}
## Set options back to original options
options(op)
```
Session info
-------------------------
```{r }
sessionInfo()
```