我正在使用 R 使用
highlight()
和串扰 filter_select()
函数制作交互式绘图。然而,当plotly线条的参数“color
”与highlight_key()
匹配时,就不可能在图中突出显示过滤数据的任何光线。
假设您在第 16.1 章“图形查询”的图 16.10 中选择了 Carson Sievert 所著的“使用 R、plotly 和闪亮的交互式基于 Web 的数据可视化”中的示例 书上提供的例子效果很好,你可以在过滤数据后突出显示一个项目:
library(gapminder)
g <- highlight_key(gapminder, ~country)
continent_filter <- filter_select("filter", "Select a country", g, ~continent)
p <- plot_ly(g) %>%
group_by(country) %>%
add_lines(x = ~year, y = ~lifeExp, color = ~continent) %>%
layout(xaxis = list(title = "")) %>%
highlight(selected = attrs_selected(showlegend = FALSE))
bscols(continent_filter, p, widths = 12)
但是,当
color
的“add_lines()
”参数与highlight_key()
变量匹配时(在本例中为~country
),无法过滤并突出显示过滤后的数据
library(gapminder)
g <- highlight_key(gapminder, ~country)
continent_filter <- filter_select("filter", "Select a country", g, ~continent)
p <- plot_ly(g) %>%
group_by(country) %>%
# Please mind that in the next line IS NOT "color = ~continent" as in the last example
add_lines(x = ~year, y = ~lifeExp, color = ~country) %>%
layout(xaxis = list(title = "")) %>%
highlight(selected = attrs_selected(showlegend = FALSE))
bscols(continent_filter, p, widths = 12)
当plotly绘图的颜色参数与highlight_key匹配时,是否可以在交互式plot_ly lineplot中突出显示项目(因为我已经签入了boxplot并且它有效)? 我也尝试过 geom_line() + ggplotly() 但都不起作用
我现在也遇到同样的问题了。每当我应用串扰 filter_select 并尝试突出显示散点图中的任何点时,它都不起作用。尽管如此,错误仍然存在!?