-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
118 lines (108 loc) · 2.92 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
eval = FALSE
)
```
# rdeck.controls
<!-- badges: start -->
<!-- badges: end -->
## Concept
```{r}
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(),
# set the bounds of the map to include all of the manhattan data
initial_bounds = st_bbox(manhattan_data$position),
# add a 2 pixel buffer to each point, making it easier to hover
picking_radius = 2,
id = "my_rdeck"
) %>%
add_scatterplot_layer(
name = "manhattan_dogs",
data = filter(manhattan_data, species_name == "dog"),
# the coloumn in manhattan_data which contains the location of each point
get_position = position,
# a categorical colour scale, using the species column and a cividis colour palette
get_fill_color = scale_color_category(
col = species,
palette = cividis(2)[[1]]
),
# the radius of each point (default 1 metre) is scaled by 30
radius_scale = 30,
radius_min_pixels = 0.5,
# highlight dot density
blending_mode = "additive",
# interactivity
pickable = TRUE,
auto_highlight = TRUE,
# per-species highlight colour
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"),
# the coloumn in manhattan_data which contains the location of each point
get_position = position,
# a categorical colour scale, using the species column and a cividis colour palette
get_fill_color = scale_color_category(
col = species,
palette = cividis(2)[[2]]
),
# the radius of each point (default 1 metre) is scaled by 30
radius_scale = 30,
radius_min_pixels = 0.5,
# highlight dot density
blending_mode = "additive",
# interactivity
pickable = TRUE,
auto_highlight = TRUE,
# per-species highlight colour
highlight_color = scale_color_category(
col = species,
palette = c("#fff399"),
legend = FALSE
),
tooltip = c(species, species_name)
)
```
```{r}
rdeck_layer_dropdown(
manhattan_map,
starts_with("manhattan"),
height = "1em !important",
label = "Select the pet type: "
)
```
```{r}
manhattan_map
```