R语言Plot_ly堆叠柱状图下拉筛选功能异常问题求助
我在使用R语言的plotly包时遇到了更新菜单(update menus)功能异常的问题。此前在chloropleth图中可行的方法,应用到堆叠柱状图时却无法正常工作,我无法确定原因。
测试代码
library(plotly) # Simplified data frame for testing test_data <- data.frame( time = rep(1:10, each = 4), total = rnorm(40, 100, 10), Species_name = rep(c("Species A", "Species B", "Species C", "Species D"), 10), mesh_grp = rep(c("Group 1", "Group 2"), 20) ) p <- test_data %>% plot_ly( x = ~time, y = ~total, split = ~Species_name, color =~Species_name, type = 'bar', transforms = list( list( type = 'filter', target = ~mesh_grp, operation = '=', value = unique(test_data$mesh_grp)[1] ) )) %>% layout( barmode = "stack", updatemenus = list( list( type = 'dropdown', active = 0, buttons = list( list(method = "restyle", args = list("transforms[0].value", unique(test_data$mesh_grp)[1]), label = unique(test_data$mesh_grp)[1]), list(method = "restyle", args = list("transforms[0].value", unique(test_data$mesh_grp)[2]), label = unique(test_data$mesh_grp)[2]) ) ) ) ) p
问题现象
按照预期,选择下拉菜单中的“Group 1”应筛选出包含Species A和Species C的数据,但实际结果显示了所有物种,且仅包含奇数时间点的数据。
请问我哪里出错了?感谢您的帮助!
内容的提问来源于stack exchange,提问作者d_lang
相关产品推荐
相关产品推荐

