forked from AdamWilsonLabEDU/SpatialDataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPS_12.Rmd
More file actions
211 lines (153 loc) · 5.66 KB
/
PS_12.Rmd
File metadata and controls
211 lines (153 loc) · 5.66 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
title: "Dynamic Visualization"
---
```{r setup, echo=F, results='hide'}
knitr::opts_knit$set(root.dir = NULL)
knitr::opts_chunk$set(fig.width=800,fig.height=400)
```
# Logistics
<iframe class='embed-responsive-item' src='schedule.html' width=100% height=700px allowfullscreen></iframe>
# HTML Visualization
## DataTables
[DataTables](http://rstudio.github.io/DT/) display R data frames as interactive HTML tables (with filtering, pagination, sorting, and search). This is a great way to make your raw data browsable without using too much space.
```{r, message=F}
library(widgetframe)
library(DT)
datatable(iris, options = list(pageLength = 5))
```
## rbokeh
Interface to the [Bokeh](http://hafen.github.io/rbokeh) library for making interactive graphics.
```{r, warning=F, message=F}
library(rbokeh)
figure(width = 800, height=400) %>%
ly_points(Sepal.Length, Sepal.Width, data = iris,
color = Species, glyph = Species,
hover = list(Sepal.Length, Sepal.Width))
```
## Leaflet
[Leaflet](http://rstudio.github.io/leaflet/) is a really powerful JavaScript library for creating dynamic maps that support panning and zooming along with various annotations like markers, polygons, and popups.
```{r, warning=F, message=F}
library(leaflet)
library(ggmap)
geocode("Buffalo, NY", source = "dsk")
m <- leaflet() %>% setView(lng = -78.88642, lat = 42.89606, zoom = 12) %>% addTiles()
```
---
```{r, echo=F}
frameWidget(m,height =500)
```
## dygraphs
Provides rich facilities for charting time-series data in R, including highly configurable series- and axis-display and interactive features like zoom/pan and series/point highlighting.
```{r, warning=F}
library(dygraphs)
dy1=dygraph(nhtemp, main = "New Haven Temperatures",height = 75) %>%
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
```
---
```{r,fig.height=600,fig.width=800, echo=F}
frameWidget(dy1,height =400)
```
## rthreejs
Create interactive 3D scatter plots, network plots, and globes using the ['three.js' visualization library](https://threejs.org).
```{r, message=F, results=F}
#devtools::install_github("bwlewis/rthreejs")
library(threejs)
z <- seq(-10, 10, 0.1)
x <- cos(z)
y <- sin(z)
js3=scatterplot3js(x, y, z, color=rainbow(length(z)))
```
---
```{r,fig.height=600,fig.width=800, echo=F}
frameWidget(js3,height =500)
```
## networkD3
Creates 'D3' 'JavaScript' network, tree, dendrogram, and Sankey graphs from 'R'.
```{r, message=F, results=F}
library(igraph)
library(networkD3)
```
## Load example network
This loads an example social network of friendships between 34 members of a karate club at a US university in the 1970s. See W. W. Zachary, An information flow model for conflict and fission in small groups, Journal of Anthropological Research 33, 452-473 (1977).
```{r}
karate <- make_graph("Zachary")
wc <- cluster_walktrap(karate)
members <- membership(wc)
# Convert to object suitable for networkD3
karate_d3 <- igraph_to_networkD3(karate, group = members)
n3d=forceNetwork(Links = karate_d3$links, Nodes = karate_d3$nodes,
Source = 'source', Target = 'target', NodeID = 'name',
Group = 'group')
```
## Force directed network plot
```{r, echo=F}
frameWidget(n3d,height =500)
```
## Sankey Network graph
Sankey diagrams are flow diagrams in which the width of the arrows is shown proportionally to the flow quantity.
```{r}
# Load energy projection data
library(jsonlite)
URL <- paste0(
"https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata/energy.json")
Energy <- fromJSON(URL)
sn1=sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "TWh", fontSize = 12, nodeWidth = 30)
```
---
```{r, echo=F}
frameWidget(sn1,height =500)
```
## Radial Network
```{r}
URL <- paste0(
"https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata//flare.json")
## Convert to list format
Flare <- jsonlite::fromJSON(URL, simplifyDataFrame = FALSE)
# Use subset of data for more readable diagram
Flare$children = Flare$children[1:3]
rn1=radialNetwork(List = Flare, fontSize = 10, opacity = 0.9, height = 400, width=400)
```
---
```{r}
frameWidget(rn1,height =500)
```
## Diagonal Network
```{r}
dn1=diagonalNetwork(List = Flare, fontSize = 10,
opacity = 0.9, height = 400, width=400)
frameWidget(dn1,height =500)
```
## Other D3 Visualizations
[https://github.com/d3/d3/wiki/Gallery](https://github.com/d3/d3/wiki/Gallery)

## rglwidget
RGL provides 3D interactive graphics, including functions modelled on base graphics (`plot3d()`, etc.) as well as functions for constructing representations of geometric objects (`cube3d()`, etc.). You may need to install [XQuartz](https://www.xquartz.org/).
```{r, message=F}
library(rgl)
library(htmltools)
theta <- seq(0, 6*pi, len=100)
xyz <- cbind(sin(theta), cos(theta), theta)
lineid <- plot3d(xyz, type="l", alpha = 1:0,
lwd = 5, col = "blue")["data"]
```
## Animate an interactive 3D process
```{r}
rg1=browsable(tagList(
rglwidget(elementId = "example", width = 800, height = 600,
controllers = "player"),
playwidget("example",
ageControl(births = theta, ages = c(0, 0, 1),
objids = lineid, alpha = c(0, 1, 0)),
start = 1, stop = 6*pi, step = 0.1,
rate = 6,elementId = "player")
))%>%save_html(file="rgl.html")
```
---
<iframe class='embed-responsive-item' src='rgl.html' width=100% height=700px allowfullscreen></iframe>
# Final Projects
## Interactive elements
Consider embedding interactive elements in your site.