if (FALSE) {
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',
options = list(width = 400, chartArea = list(width = "50%")))
google_map() %>%
add_markers(data = tram_stops, info_window = chartList, id = "stop_id")
tram_route$id <- c(rep(1, 30), rep(2, 25))
lineCharts <- data.frame(id = rep(c(1,2), each = 2),
year = rep( c("year1", "year2") ),
arrivals = sample(1:100, size = 4),
departures = sample(1:100, size = 4))
chartList <- list(data = lineCharts,
type = 'area')
google_map() %>%
add_polylines(data = tram_route, id = 'id',
stroke_colour = "id", stroke_weight = 10,
lat = "shape_pt_lat", lon = "shape_pt_lon",
info_window = chartList
)
}
if (FALSE) {
## 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")
lineChart <- data.frame(id = 33,
year = c("year1","year2"),
val1 = c(1,2),
val2 = c(2,1))
chartList <- list(data = lineChart, type = 'bar')
google_map() %>%
add_polylines(data = melbourne[melbourne$polygonId == 33, ],
polyline = "polyline",
info_window = chartList)
}
if (FALSE) {
## 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")
}
if (FALSE) {
## 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")
}
if (FALSE) {
## 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")
polyChart <- data.frame(id = 33,
year = c("year1","year2"),
val1 = c(1,2),
val2 = c(2,1))
chartList <- list(data = polyChart, type = 'column')
google_map() %>%
add_polygons(data = melbourne[melbourne$polygonId == 33, ],
polyline = "polyline",
info_window = chartList)
tram_route$id <- 1
polyChart <- data.frame(id = 1,
year = c("year1","year2"),
val1 = c(1,2),
val2 = c(2,1))
chartList <- list(data = polyChart, type = 'column')
google_map() %>%
add_polygons(data = tram_route,
lon = "shape_pt_lon", lat = "shape_pt_lat",
info_window = chartList)
}
if (FALSE) {
## 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_circles(data = tram_stops, info_window = chartList, id = "stop_id")
}
if (FALSE) {
## 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_circles(data = tram_stops, info_window = chartList, id = "stop_id")
}
if (FALSE) {
## Line
markerCharts <- data.frame(stop_id = rep(tram_stops$stop_id, each = 20),
day = as.character(1:20),
value = sample(1:100, size = nrow(tram_stops) * 20, replace = T))
chartList <- list(data = markerCharts,
type = 'line')
google_map() %>%
add_circles(data = tram_stops, info_window = chartList, id = "stop_id")
}
if (FALSE) {
## 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")
}
if (FALSE) {
## 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")
}
Run the code above in your browser using DataLab