r - 如何在串扰过滤器后突出显示()线图
问题描述
highlight()
我正在使用 R 使用和串扰filter_select()
功能制作交互式绘图。但是,当color
plotly 的 lines 的参数“” matchhighlight_key()
时,无法突出显示图中过滤数据的任何光线。
假设你拿起 Carson Sievert 的“使用 R、plotly 和闪亮的交互式 web 数据可视化”中的示例,在第 16.1 章“图形查询”的图 16.10 书中提供的示例工作正常,您可以过滤数据后突出显示一个项目:
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 线图中突出显示项目(因为我已经检查了箱线图并且它有效)?我也尝试过 geom_line() + ggplotly() 但也不起作用
解决方案
推荐阅读
- java - 错误: ';' 预期 - 不确定如何调试或导致错误的原因
- c# - 属性初始化和比较时间
- amazon-web-services - 将 aws 凭据传递给厨房 ec2 命令行
- c++ - C++ 创建一个 10x10 的网格,每个点都有一个随机字符?
- php - 如何修复在此服务器上找不到请求的 URL。而其他计算机可以访问
- javascript - 不和谐.JS | TypeError:无法读取 null 的属性“运行”
- wordpress - 直接访问 wp-cron.php
- lua - Roblox Studio Lua:杀死脚本问题的现金
- android - 安卓。触摸侦听器在两个视图之间混合
- javascript - 针对浏览器窗口大小?