如何在串扰过滤器后突出显示()线图

问题描述 投票:0回答:1

我正在使用 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() 但都不起作用

r plotly data-visualization r-plotly htmlwidgets
1个回答
0
投票

我现在也遇到同样的问题了。每当我应用串扰 filter_select 并尝试突出显示散点图中的任何点时,它都不起作用。尽管如此,错误仍然存在!?

© www.soinside.com 2019 - 2024. All rights reserved.