forked from SymbolixAU/googleway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_charts.Rd
446 lines (314 loc) · 12.6 KB
/
google_charts.Rd
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/charts.R
\name{google_charts}
\alias{google_charts}
\title{Google Charts}
\description{
Google Charts can be displayed inside an \code{info_window}
}
\section{\code{info_window}}{
When using a chart in an \code{info_window} you need to pass in a \code{list} with at least
two elements named \code{data} and \code{type}. You can also use a third element called \code{options}
for controlling the appearance of the chart.
You must also supply the \code{id} argument to the layer your are adding (e.g. \code{add_markers()}),
and the \strong{\code{data}} must have a column with the same name as the \code{id} (and therefore
the same name as the \code{id} column in the original \code{data} supplied to the \code{add_} function).
See the specific chart sections for details on how to structure the \code{data}.
}
\section{chart types}{
the \code{type} element can be one of
\itemize{
\item \code{area}
\item \code{bar}
\item \code{bubble}
\item \code{candlestick}
\item \code{column}
\item \code{combo}
\item \code{histogram}
\item \code{line}
\item \code{pie}
\item \code{scatter}
}
}
\section{Area}{
\strong{data}
An area chart requires a \code{data.frame} of at least three columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third or more columns: the data used in the chart
}
\strong{type} - \code{area}
\strong{options}
see the area charts documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/areachart}
Each row of data represents a data point at the same x-axis location
}
\section{Bar}{
\strong{data}
A bar chart requires a \code{data.frame} of at least three columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third or more columns: the data used in the chart
}
\strong{type} - \code{bar}
\strong{options}
See the bar chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/barchart}
}
\section{Bubble}{
\strong{data}
A bubble chart requires a \code{data.frame} of at least four, and at most six columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third column: x-axis value
\item Fourth column: y-axis value
\item Fith column: visualised as colour
\item Sixth column: visualised as size
}
\strong{type} - \code{bubble}
\strong{options}
See the bubble chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/bubblechart}
}
\section{Candlestick}{
\strong{data}
A candlestick chart requires a \code{data.frame} of at least six columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third column: Number specifying the 'low' number for the data
\item Fourth column: Number specifying the opening/initial value of the data.
This is one vertical border of the candle. If less than the column 4 value,
the candle will be filled; otherwise it will be hollow.
\item Fith column: Number specifying the closing/final value of the data.
This is the second vertical border of the candle. If less than the column 3 value,
the candle will be hollow; otherwise it will be filled.
\item Sixth column: Number specifying the high/maximum value of this marker.
This is the top of the candle's center line.
}
\strong{type} - \code{candlestick}
\strong{options}
See the candlestick chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/candlestickchart}
}
\section{Column}{
\strong{data}
A column chart requires a \code{data.frame} of at least three columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third or more columns: the data used in the chart
}
\strong{type} - \code{column}
\strong{options}
See the column chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/columnchart}
}
\section{Combo}{
A Combo chart lets you render each series as a different marker type from the following list:
line, area, bars, candlesticks, and stepped area.
\strong{data}
A combo chart requires a \code{data.frame} of at least three columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third or more columns: the data used in the chart
}
\strong{type} - \code{combo}
\strong{options}
See the column chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/columnchart}
}
\section{Histogram}{
\strong{data}
A column chart requires a \code{data.frame} of at least three columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third or more columns: the data used in the chart
}
\strong{type} - \code{histogram}
\strong{options}
See the histogram chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/histogram}
}
\section{Pie}{
\strong{data}
A Pie chart requires a \code{data.frame} of three columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third column: the data used in the chart
}
\strong{type} - \code{pie}
\strong{options}
See the pie chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/piechart}
}
\section{Scatter}{
\strong{data}
A Scatter chart requires a \code{data.frame} of at least four columns:
\enumerate{
\item First column: a column of id values, where the column has the same name as the
id column in the \code{data} argument, and therefore the same name as the value supplied
to the \code{id} argument.
\item Second column: variable names used for labelling the data
\item Third column: the data plotted on x-axis
\item Fourth or more columns: the data plotted on y-axis
}
\strong{type} - \code{scatter}
\strong{options}
See the scatter chart documentation for various other examples
\url{https://developers.google.com/chart/interactive/docs/gallery/scatterchart}
}
\examples{
\dontrun{
set_key("your_api_key")
## AREA
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 2),
year = rep( c("year1", "year2")),
arrivals = sample(1:100, size = nrow(tram_stops) * 2, replace = T),
departures = sample(1:100, size = nrow(tram_stops) * 2, replace = T))
chartList <- list(data = markerCharts,
type = 'area')
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## BAR
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 2),
year = rep( c("year1", "year2")),
arrivals = sample(1:100, size = nrow(tram_stops) * 2, replace = T),
departures = sample(1:100, size = nrow(tram_stops) * 2, replace = T))
chartList <- list(data = markerCharts,
type = 'bar')
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## BUBBLE
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 4),
ID = sample(letters, size = nrow(tram_stops) * 4, replace = T),
time = sample(1:1440, size = nrow(tram_stops) * 4, replace = T),
passengers = sample(1:100, size = nrow(tram_stops) * 4, replace = T),
year = c("year1", "year2", "year3", "year4"),
group = sample(50:100, size = nrow(tram_stops) * 4, replace = T))
chartList <- list(data = markerCharts,
type = 'bubble')
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## CANDLESTICK
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 5),
day = rep(c("Mon", "Tues", "Weds", "Thurs", "Fri"), times = nrow(tram_stops) ),
val1 = rep(c(20, 31, 50, 77, 68), times = nrow(tram_stops) ),
val2 = rep(c(28, 38, 55, 77, 66), times = nrow(tram_stops) ),
val3 = rep(c(38, 55, 77, 66, 22), times = nrow(tram_stops) ),
val4 = rep(c(45, 66, 80, 50, 15), times = nrow(tram_stops) ) )
chartList <- list(data = markerCharts,
type = 'candlestick',
options = list(legend = 'none',
bar = list(groupWidth = "100\%"),
candlestick = list(
fallingColor = list( strokeWidth = 0, fill = "#a52714"),
risingColor = list( strokeWidth = 0, fill = "#0f9d58")
)
))
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## COLUMN
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 2),
year = rep( c("year1", "year2")),
arrivals = sample(1:100, size = nrow(tram_stops) * 2, replace = T),
departures = sample(1:100, size = nrow(tram_stops) * 2, replace = T))
chartList <- list(data = markerCharts,
type = 'column')
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## COMBO
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 2),
year = rep( c("year1", "year2")),
arrivals = sample(1:100, size = nrow(tram_stops) * 2, replace = T),
departures = sample(1:100, size = nrow(tram_stops) * 2, replace = T))
markerCharts$val <- sample(1:100, size = nrow(markerCharts), replace = T)
chartList <- list(data = markerCharts,
type = 'combo',
options = list(
"title" = "Passengers at stops",
"vAxis" = list( title = "passengers" ),
"hAxis" = list( title = "load" ),
"seriesType" = "bars",
"series" = list( "2" = list( "type" = "line" )))) ## 0-indexed
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## HISTOGRAM
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 20),
day = as.character(1:20))
markerCharts$wait <- rnorm(nrow(markerCharts), 0, 1)
chartList <- list(data = markerCharts,
type = 'histogram')
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## PIE
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 3))
markerCharts$variable <- c("yes", "no", "maybe")
markerCharts$value <- sample(1:10, size = nrow(markerCharts), replace = T)
chartList <- list(data = markerCharts,
type = 'pie',
options = list(title = "my pie",
is3D = TRUE,
height = 240,
width = 240,
colors = c('#440154', '#21908C', '#FDE725')))
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
## use pieHole option to make a donut chart
chartList <- list(data = markerCharts,
type = 'pie',
options = list(title = "my pie",
pieHole = 0.4,
height = 240,
width = 240,
colors = c('#440154', '#21908C', '#FDE725')))
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
\dontrun{
## SCATTER
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 5))
markerCharts$arrival <- sample(1:10, size = nrow(markerCharts), replace = T)
markerCharts$departure <- sample(1:10, size = nrow(markerCharts), replace = T)
chartList <- list(data = markerCharts,
type = 'scatter')
google_map() \%>\%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
}
}