rdeck.controls
Concept
library(tidyverse)
library(rdeck)
library(sf)
library(RcppSimdJson)
library(viridis)
library(rdeck.controls)
url <- file.path(
"https://raw.githubusercontent.com/visgl/deck.gl-data/master",
"examples/scatterplot/manhattan.json",
fsep = "/"
)
manhattan_data <- fload(url) %>%
as_tibble(.name_repair = ~ c("lon", "lat", "species")) %>%
mutate(
position = sfc_point(lon, lat),
species_name = if_else(species == 1, "dog", "cat")
)
manhattan_map <-
rdeck(
map_style = mapbox_dark(),
initial_bounds = st_bbox(manhattan_data$position),
picking_radius = 2,
id = "my_rdeck"
) %>%
add_scatterplot_layer(
name = "manhattan_dogs",
data = filter(manhattan_data, species_name == "dog"),
get_position = position,
get_fill_color = scale_color_category(
col = species,
palette = cividis(2)[[1]]
),
radius_scale = 30,
radius_min_pixels = 0.5,
blending_mode = "additive",
pickable = TRUE,
auto_highlight = TRUE,
highlight_color = scale_color_category(
col = species,
palette = c("#0060e6"),
legend = FALSE
),
tooltip = c(species, species_name)
) %>%
add_scatterplot_layer(
name = "manhattan_cats",
data = filter(manhattan_data, species_name == "cat"),
get_position = position,
get_fill_color = scale_color_category(
col = species,
palette = cividis(2)[[2]]
),
radius_scale = 30,
radius_min_pixels = 0.5,
blending_mode = "additive",
pickable = TRUE,
auto_highlight = TRUE,
highlight_color = scale_color_category(
col = species,
palette = c("#fff399"),
legend = FALSE
),
tooltip = c(species, species_name)
)
rdeck_layer_dropdown(
manhattan_map,
starts_with("manhattan"),
height = "1em !important",
label = "Select the pet type: "
)
manhattan_map