与下拉菜单一起更改数据的合唱。痕迹未显示
我正在尝试制作一个唱片地图,在该地图中,用户可以使用下拉菜单使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论