与下拉菜单一起更改数据的合唱。痕迹未显示

发布于 2025-01-27 17:52:00 字数 1196 浏览 4 评论 0原文

我正在尝试制作一个唱片地图,在该地图中,用户可以使用下拉菜单使用R中的绘图在不同的变量之间进行更改。 在使用线图进行类似的操作时,我可以将第二个跟踪的可见性设置为false,并使用按钮更改不同跟踪的可见性,如下所示。但是,当使用plot_geo()时,图仅更改颜色,数据和HoverInfo不会更改。另外,一旦使用滑块,颜色就会立即切换回第一个迹线。

如果用户选择“ STAT2”,我希望该图仅显示此变量的数据,颜色和HoverInfo。

提前致谢!

df <- data.frame(year=c(rep(2000,5), rep(2001,5), rep(2002,5), rep(2003,5), rep(2004,5), rep(2005,5)),
                 stat1=sample(1:10, 30, replace=T),
                 stat2=sample(1:100, 30),
                 location=rep(c("DEU", "BEL", "FRA", "ITA", "SWE", "FIN"),5))

                 y=1,# position the button
                 buttons = list(  
                   list(method="update",
                        args=list(list(visible=list(T,F))),
                        label="stat1"), 
                   list(method="update",
                        args=list(list(visible=list(F,T))),
                        label="stat2")))

plot_geo(df, frame=~year) %>% 
  add_trace(locations=~location, z=~stat1, color=~stat1, colorscale="Blues") %>%
  add_trace(locations=~location, z=~stat1, color=~stat2, colorscale="Greys", visible=F) %>%
  layout(geo=list(scope="europe"),
         updatemenus=list(button))

i am trying to produce a choropleth map in which the user can use a dropdown menu to change between different variables using plotly in R.
When doing something similar with a line chart, I could set the visibility of the second trace to FALSE and use a button to change the visibility of the different traces, as shown in the code below. However, when using plot_geo(), the plot only changes the color, the data and hoverinfo does not change. Also, the color switches back to the first trace as soon as the slider gets used.

If the user selects "stat2", I want the plot to only show the data, color and hoverinfo for this variable.

Thanks in advance!

df <- data.frame(year=c(rep(2000,5), rep(2001,5), rep(2002,5), rep(2003,5), rep(2004,5), rep(2005,5)),
                 stat1=sample(1:10, 30, replace=T),
                 stat2=sample(1:100, 30),
                 location=rep(c("DEU", "BEL", "FRA", "ITA", "SWE", "FIN"),5))

                 y=1,# position the button
                 buttons = list(  
                   list(method="update",
                        args=list(list(visible=list(T,F))),
                        label="stat1"), 
                   list(method="update",
                        args=list(list(visible=list(F,T))),
                        label="stat2")))

plot_geo(df, frame=~year) %>% 
  add_trace(locations=~location, z=~stat1, color=~stat1, colorscale="Blues") %>%
  add_trace(locations=~location, z=~stat1, color=~stat2, colorscale="Greys", visible=F) %>%
  layout(geo=list(scope="europe"),
         updatemenus=list(button))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文