Closed SymbolixAU closed 6 years ago
library(sf)
library(geojsonsf)
sf <- geojson_sf("https://symbolixau.github.io/data/geojson/SA2_2016_VIC.json")
sf <- sf::st_cast(sf, "POLYGON")
set_token(read.dcf("~/Documents/.googleAPI", fields = "MAPBOX"))
m <- mapdeck::mapdeck(
style = 'mapbox://styles/mapbox/dark-v9'
, location = c(144.5, -37)
, zoom = 5)
library(microbenchmark)
sf <- rbind(sf, sf, sf, sf, sf, sf)
sf <- rbind(sf, sf, sf, sf, sf)
sf <- rbind(sf, sf, sf)
# sf <- rbind(sf, sf, sf, sf, sf)
sf$n <- 1:nrow(sf)
microbenchmark(
old = {
p <- add_polygon_old(
map = m
, data = sf
, layer = "polygon_layer"
, fill_colour = "SA2_NAME16"
)
},
new = {
p <- add_polygon(
map = m
, data = sf
, layer = "polygon_layer"
, fill_colour = "SA2_NAME16"
)
},
times = 3
)
# nrow(sf)
# 554400
# fill_colour == 'n'
# Unit: seconds
# expr min lq mean median uq max neval
# old 11.703587 11.74221 11.78442 11.780833 11.824836 11.868838 3
# new 5.637217 5.67257 5.69053 5.707923 5.717187 5.726451 3
# fill_colour = "SA2_NAME16"
# Unit: seconds
# Unit: seconds
# expr min lq mean median uq max neval
# old 8.017775 8.066077 8.097923 8.114378 8.137996 8.161614 3
# new 5.497510 5.542538 5.561584 5.587566 5.593622 5.599677 3
lons <- seq(-180, 180, by = 0.0001)
lats <- seq(-90, 90, by = 0.0001)
n <- 1e5
df <- data.frame(
# id = sample(letters[1:10], size = 26, replace = T)
id = 1:n
# id = seq(as.Date("2018-01-01"), as.Date("2018-01-26"), by = 1)
# id = as.factor(1:26)
, lon = sample(lons, size = n, replace = T)
, lat = sample(lats, size = n, replace = T)
, l = sample(letters, size = n, replace = T)
, r = 1:n
, s = rnorm(n)
, stringsAsFactors = F
)
set_token(read.dcf("~/Documents/.googleAPI", fields = "MAPBOX"))
m <- mapdeck::mapdeck()
library(microbenchmark)
microbenchmark(
old = {
old <- add_pointcloud_old(
map = m
, data = df
, lat = "lat"
, lon = "lon"
, radius = 1000
, fill_colour = "l"
#, fill_opacity = "id"
, tooltip = "id"
)
},
new = {
new <- add_pointcloud(
map = m
, data = df
, lat = "lat"
, lon = "lon"
, radius = 1000
, fill_colour = "l"
#, fill_opacity = "id"
, tooltip = "id"
)
},
times = 5
)
# n <- 1e5
# fill_colour = 'id'
# Unit: milliseconds
# expr min lq mean median uq max neval
# old 7485.5636 7686.8731 7859.4077 7946.2620 8040.5643 8137.7754 5
# new 251.0061 268.0089 381.0152 393.0107 493.9947 499.0555 5
# fill_colour = 'l'
# Unit: milliseconds
# expr min lq mean median uq max neval
# old 258.9929 320.5041 386.6248 358.1111 448.0709 547.4450 5
# new 173.4745 183.2885 202.0799 188.7792 225.8983 238.9591 5
set_token(read.dcf("~/Documents/.googleAPI", fields = "MAPBOX"))
m <- mapdeck::mapdeck()
library(microbenchmark)
microbenchmark(
old = {
old <- add_line_old(
map = m
, data = flights
, layer_id = "line_layer"
, origin = c("start_lon", "start_lat")
, destination = c("end_lon", "end_lat")
, stroke_colour = "cnt"
, stroke_width = "stroke"
, auto_highlight = TRUE
, legend = TRUE
)
},
new = {
new <- add_line(
map = m
, data = flights
, layer_id = "line_layer"
, origin = c("start_lon", "start_lat")
, destination = c("end_lon", "end_lat")
, stroke_colour = "cnt"
, stroke_width = "stroke"
, auto_highlight = TRUE
, legend = TRUE
)
},
times = 5
)
# Unit: milliseconds
# expr min lq mean median uq max neval
# old 17.486042 17.636939 64.697349 19.485457 57.684504 211.193804 5
# new 1.070719 1.106256 1.127582 1.127063 1.146071 1.187801 5
microbenchmark(
old = {
old <- add_arc_old(
map = m
, data = flights
, layer_id = "arc_layer"
, origin = c("start_lon", "start_lat")
, destination = c("end_lon", "end_lat")
, stroke_from = "airport1"
, stroke_to = "airport2"
, stroke_width = "stroke"
, tooltip = "info"
, auto_highlight = TRUE
)
},
new = {
new <- add_arc(
map = m
, data = flights
, layer_id = "arc_layer"
, origin = c("start_lon", "start_lat")
, destination = c("end_lon", "end_lat")
, stroke_from = "airport1"
, stroke_to = "airport2"
, stroke_width = "stroke"
, tooltip = "info"
, auto_highlight = TRUE
)
},
times = 5
)
# Unit: milliseconds
# expr min lq mean median uq max neval
# old 31.323071 32.116434 35.943007 33.199587 35.084571 47.991374 5
# new 1.180305 1.186721 1.311459 1.199241 1.442029 1.549001 5
TODO - layers
TODO
add_path()
colours are differentadd_path()
don't colour twice if the same variable is used for stroke & fillTODO - legend
colourvalues::colour_values()
asks for summary, but, it's not used)fill_colour
, it still needs to make a colour from the 'default' colourTODO - other