File: sf-mapbox-data.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (35 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download | duplicates (4)
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
library(plotly)
library(crosstalk)

# one trace
plot_mapbox(res_mn)
plot_mapbox(res_mn, stroke = I("#119dff"), span = I(1), color = I("#00cc96"))

# multiple traces 
plot_mapbox(res_mn, split = ~INDRESNAME, span = I(1))
plot_mapbox(res_mn, split = ~INDRESNAME, color = ~AREA, stroke = ~PERIMETER, span = I(1))

# linking with DT
mn <- highlight_key(res_mn)
bscols(
  plot_mapbox(mn, split = ~INDRESNAME, text = ~INDRESNAME, hoverinfo = "text", hoveron = "fills") %>%
    layout(title = "Click a reservation", showlegend = FALSE),
  DT::datatable(mn)
)

# linking with plotly
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ncsd <- highlight_key(nc)

# note that brushing counties is currently possible with plot_ly(), but isn't quite working 
# yet with plot_mapbox() -- https://github.com/plotly/plotly.js/issues/2512
bscols(
  plot_mapbox(ncsd) %>%
    highlight(dynamic = TRUE, persistent = TRUE),
  plot_ly(ncsd, x = ~AREA) %>% 
    add_histogram(xbins = list(start = 0, end = 0.3, size = 0.02)) %>%
    layout(barmode = "overlay") %>% 
    highlight("plotly_selected", persistent = TRUE)
)