【发布时间】:2021-09-15 10:17:00
【问题描述】:
我正在使用 R 编程语言。从之前的帖子 (R: Plot not Fully Loading) 中,我学会了如何在 R 中使用 plotly 制作交互式绘图:
library(plotly)
iris %>% plot_ly(type = 'parcoords', line = list(color = ~as.integer(Species),
colorscale = list(c(0,'red'),c(0.5,'green'),c(1,'blue'))),
dimensions = list( list(range = c(2,4.5), label = 'Sepal Width', values = ~Sepal.Width),
list(range = c(4,8), constraintrange = c(5,6), label = 'Sepal Length', values = ~Sepal.Length),
list(range = c(0,2.5), label = 'Petal Width', values = ~Petal.Width),
list(range = c(1,7), label = 'Petal Length', values = ~Petal.Length) ) )
假设我要在数据集中添加一个“id”列,例如
library(dplyr)
df <- iris %>% mutate(id = row_number())
是否有可能,当您“单击”此图上的任何“线”时,会出现与该行对应的数据集(即“df”)信息?
谢谢
【问题讨论】:
-
这个github issue看起来可能和这个有关。
-
@Ben:你知道如何调整这段代码以解决我正在处理的问题吗?
-
你可以参考这个plotly.com/ggplot2/interactive-tooltip也许它可以帮助你:)
标签: r dplyr hover plotly tooltip