如何在串扰滤波器之后高亮显示()线图

时间:2019-05-29 15:06:18

标签: r plotly data-visualization htmlwidgets

我正在使用highlight()和串扰filter_select()函数使用R进行交互式绘图。但是,当plotly的行的自变量“ color”与highlight_key()相匹配时,将无法突出显示图中已过滤数据的任何光线。

比方说,您在Figure 16.10 of the chapter 16.1 "Graphical queries"的Carson Sievert的“基于Web的交互式Web数据可视化中获得了R,密谋而又有光泽”示例中 本书提供的示例效果很好,您可以在过滤数据后突出显示一个项目:

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)

enter image description here

但是,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)

enter image description here

当plotly的图的color参数与highlight_key匹配时,是否可以突出显示交互式plot_ly线图中的项(因为我已经在boxplot中签入并且可以工作)? 我也尝试过使用geom_line()+ ggplotly(),但两者都不起作用

0 个答案:

没有答案