r - Multiple traces not working in plot_geo -
i trying create scattergeo map using r plotly package version 4.5.2. geographic scope new south wales (australia) , need include district boundaries within state, cannot use 1 of existing plotly geo scopes.
my attempted work around plot district boundaries using add_paths()
(applied data frame boundary info), , overlay scatter data using add_markers(inherit = false)
(to different data frame). however, final result not render many of desired visual attributes markers (e.g. marker colors grey [as per boundary lines], rather green , blue, , sizes attributes ignored). see first screen shot.
but when remove add_paths()
plot pipeline, markers rendered perfectly. see second screen shot.
any suggestions how can make work? reproducible code simplified data frames below. session info below.
plotly screenshot - grey boundaries markers rendered incorrectly
plotly screenshot - markers rendered correctly no boundaries
library(plotly) # data "scatter bubbles" dat <- data.frame( aviation_id = c("ayam", "bbax", "bddx", "begx", "bell", "cbmr"), latitude = c(-29.4333, -37.0016, -35.4253, -36.6722, -34.3691, -35.9371), longitude = c( 153.3633, 149.2336, 149.7835, 149.8191, 150.9291, 148.3779), rmse = c(1.303055, 2.114968, 2.459223, 2.841459, 1.238029, 2.125925), rmse_group = c("[1,2)", "[2,3)", "[2,3)", "[2,3)", "[1,2)", "[2,3)"), tooltip_label = c("ayam<br>rmse: 1.3", "bbax<br>rmse: 2.11", "bddx<br>rmse: 2.46", "begx<br>rmse: 2.84", "bell<br>rmse: 1.24", "cbmr<br>rmse: 2.13") ) # district boundaries boundaries <- data.frame( district = c("nsw_01", "nsw_01", "nsw_01", "nsw_01", "nsw_01", "nsw_02", "nsw_02", "nsw_02", "nsw_02"), lat = c(-29, -32, -32.5, -29, -29, -37, -35, -34, -37), lon = c(153.5, 153, 150.5, 150, 153.5, 149, 148, 151, 149) ) # geo layout lat_range <- c(-38, -27.5) lon_range <- c(140, 155) g1 <- list( showcoastlines = false, lonaxis = list( showgrid = true, gridwidth = 0.5, range = lon_range, dtick = 5 ), lataxis = list( showgrid = true, gridwidth = 0.5, range = lat_range, dtick = 5 ) ) # scatter marker attributes rmse_markers <- list( line = list(color = "black", opacity = .7, width = 1.75), opacity = .8, sizemode = "diameter" ) # plot plot_geo() %>% add_paths(data = boundaries, x = ~lon, y = ~lat, color = ~district, colors = c("grey", "grey"), line = list(width = 2), showlegend = false) %>% add_markers(data = dat, x = ~longitude, y = ~latitude, color = ~rmse_group, colors = c("[0,1)" = "yellow", "[1,2)" = "green", "[2,3)" = "blue", "[3,infty)" = "red"), size = ~rmse, sizes= 8*c(min(dat$rmse),max(dat$rmse)), marker = rmse_markers, text = ~tooltip_label, hoverinfo = "text", inherit = false) %>% layout(geo = g1)
note: in older version of plotly able work, have tried in v4.5.2 without luck.
session info:
> sessioninfo() r version 3.3.1 (2016-06-21) platform: x86_64-w64-mingw32/x64 (64-bit) running under: windows >= 8 x64 (build 9200) locale: [1] lc_collate=english_australia.1252 lc_ctype=english_australia.1252 lc_monetary=english_australia.1252 [4] lc_numeric=c lc_time=english_australia.1252 attached base packages: [1] stats graphics grdevices utils datasets methods base other attached packages: [1] plotly_4.5.2 ggplot2_2.1.0 loaded via namespace (and not attached): [1] rcpp_0.12.6 tidyr_0.6.0 viridislite_0.1.3 digest_0.6.10 dplyr_0.5.0 assertthat_0.1 grid_3.3.1 [8] plyr_1.8.4 r6_2.1.2 jsonlite_1.0 gtable_0.2.0 dbi_0.4-1 magrittr_1.5 scales_0.4.0 [15] httr_1.2.1 lazyeval_0.2.0 tools_3.3.1 htmlwidgets_0.7 purrr_0.2.2 munsell_0.4.3 yaml_2.1.13 [22] base64enc_0.1-3 colorspace_1.2-6 htmltools_0.3.5 tibble_1.1
the problem fixed specifying scales when initiating object.
i posted simplified example of issue on github, answered cpsievert:
Comments
Post a Comment