|
1 |
| -library(sf) |
2 |
| - |
3 |
| -plot_mapbox(res_mn) |
4 |
| -plot_mapbox(res_mn, split = ~INDRESNAME) |
5 |
| - |
6 |
| - |
7 |
| -library(sf) |
8 | 1 | library(plotly)
|
| 2 | +library(crosstalk) |
9 | 3 |
|
10 |
| -nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) |
11 |
| - |
12 |
| -# can set multiple bounding boxes and overwrite attributes |
13 |
| -subplot( |
14 |
| - plot_mapbox(nc), |
15 |
| - plot_mapbox(nc, fillcolor = "gray", line = list(size = 0.01, color = "black")) |
| 4 | +# one trace |
| 5 | +plot_mapbox(res_mn) |
| 6 | +plot_mapbox(res_mn, stroke = I("#119dff"), span = I(1), color = I("#00cc96")) |
| 7 | + |
| 8 | +# multiple traces |
| 9 | +plot_mapbox(res_mn, split = ~INDRESNAME, span = I(1)) |
| 10 | +plot_mapbox(res_mn, split = ~INDRESNAME, color = ~AREA, stroke = ~PERIMETER, span = I(1)) |
| 11 | + |
| 12 | +# linking with DT |
| 13 | +mn <- crosstalk::SharedData$new(res_mn) |
| 14 | +bscols( |
| 15 | + plot_mapbox(mn, split = ~INDRESNAME, text = ~INDRESNAME, hoverinfo = "text", hoveron = "fill") %>% |
| 16 | + layout(title = "Click a reservation", showlegend = FALSE), |
| 17 | + DT::datatable(mn) |
16 | 18 | )
|
17 | 19 |
|
18 |
| -# map custom hover text to each point |
19 |
| -# (unfortunately, scattermapbox does not yet support hoveron='fill') |
20 |
| -plot_mapbox(nc, text = ~paste0(NAME, ": ", AREA), hoverinfo = "text") |
21 |
| - |
22 |
| - |
23 |
| -col_scale <- scales::col_numeric("Blues", range(nc$AREA)) |
24 |
| -plot_ly(nc, fillcolor = ~col_scale(AREA), text = ~AREA, hoveron = "fill") %>% |
25 |
| - layout(showlegend = FALSE) |
26 |
| - |
27 |
| -# TODO: animation |
| 20 | +nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) |
| 21 | +ncsd <- SharedData$new(nc) |
28 | 22 |
|
29 | 23 |
|
30 |
| -# TODO: click to highlight |
31 |
| -ncsd <- crosstalk::SharedData$new(nc) |
32 |
| -plot_mapbox(ncsd) |
33 |
| - |
34 |
| - |
35 |
| -# TODO: perhaps during verification, if hoveron = 'fill' for a given trace, |
36 |
| -# we could check if text is unique or not...if it is, just take first element |
37 |
| -plot_mapbox(nc, split = ~AREA, text = ~NAME, hoveron = "fill") |
38 |
| - |
39 |
| -# TODO: how to best control hoverinfo? |
40 |
| - |
41 |
| - |
42 |
| - |
43 |
| -# non-standard crs |
44 |
| -library(mapview) |
45 |
| -plot_mapbox(trails) |
46 |
| - |
| 24 | +# note that brushing counties is currently possible with plot_ly(), but isn't quite working |
| 25 | +# yet with plot_mapbox() -- https://github.com/plotly/plotly.js/issues/2512 |
| 26 | +bscols( |
| 27 | + plot_mapbox(ncsd) %>% |
| 28 | + highlight(dynamic = TRUE, persistent = TRUE), |
| 29 | + plot_ly(ncsd, x = ~AREA) %>% |
| 30 | + add_histogram(xbins = list(start = 0, end = 0.3, size = 0.02)) %>% |
| 31 | + layout(barmode = "overlay") %>% |
| 32 | + highlight("plotly_selected", persistent = TRUE) |
| 33 | +) |
47 | 34 |
|
48 | 35 |
|
0 commit comments