我试图制作一个应该相当简单的情节剧情,但是我遇到了一些困难。
我想要做的是绘制每个纬度和长度,并根据计数列为它们着色。如果我将鼠标悬停在某个位置,我会在名称字段中看到该名称。
我觉得好像下面的代码很接近,但正如您所说,我没有任何悬停功能。
library(plotly)
#note you might need a token from here: https://www.mapbox.com/help/how-access-tokens-work/
Sys.setenv("MAPBOX_TOKEN" = "my_token")
data <- structure(list(lat = c(32.6310392784338, 32.1837229125793, 31.7739571914213,
32.4667576871354, 31.549376888011, 32.7433574730586), lon = c(-97.1339747215662,
-97.5812910874207, -97.9910568085787, -97.2982563128646, -98.215637111989,
-97.0216565269414), count = c(1, 2, 5, 15, 20, 35), name = c("text_to_display1",
"text_to_display2", "text_to_display3", "text_to_display4", "text_to_display5",
"text_to_display6")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-6L), .Names = c("lat", "lon", "count", "name"))
plot_ly <- data %>%
plot_mapbox(lat = ~lat,
lon = ~lon,
#split = ~count,
color = ~count,
colors = RColorBrewer::brewer.pal(n = 9, name = "Blues"),
mode = 'markers') %>%
layout(title = 'A Title',
font = list(color='white'),
plot_bgcolor = '#191A1A', paper_bgcolor = '#191A1A',
mapbox = list(style = 'dark'),
legend = list(orientation = 'h',
font = list(size = 8)),
margin = list(l = 25, r = 25,
b = 25, t = 25,
pad = 2),
showlegend = FALSE)
plot_ly
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2 RColorBrewer_1.1-2 readr_1.1.1 plotly_4.7.1
[5] ggplot2_2.2.1 devtools_1.13.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 git2r_0.19.0 plyr_1.8.4 bindr_0.1
[5] tools_3.3.3 digest_0.6.12 viridisLite_0.2.0 jsonlite_1.5
[9] evaluate_0.10 memoise_1.0.0 tibble_1.3.3 gtable_0.2.0
[13] pkgconfig_2.0.1 rlang_0.1.1 rstudioapi_0.7 shiny_1.0.3
[17] crosstalk_1.0.0 curl_2.4 yaml_2.1.14 withr_2.1.0
[21] httr_1.2.1 stringr_1.2.0 dplyr_0.7.2 knitr_1.18
[25] hms_0.3 htmlwidgets_0.9 rprojroot_1.2 grid_3.3.3
[29] glue_1.1.1 data.table_1.10.4 R6_2.2.1 rmarkdown_1.8
[33] tidyr_0.6.3.9000 purrr_0.2.2.2 magrittr_1.5 backports_1.0.5
[37] scales_0.4.1 htmltools_0.3.6 rsconnect_0.7 assertthat_0.2.0
[41] xtable_1.8-2 mime_0.5 colorspace_1.3-2 httpuv_1.3.5
[45] stringi_1.1.5 lazyeval_0.2.0 munsell_0.4.3