我正在尝试做类似的事情How to choose variable to display in tooltip when using ggplotly?
但不同之处在于我有两个时间序列,并且该链接中建议的解决方案不起作用。所以这就是我尝试过的:
library(ggplot2)
library(plotly)
library(dplyr)
t = rnorm(10, 0, 1)
x = rnorm(10, 0, 1)
y = rnorm(10, 0, 1)
z = rnorm(10, 0, 1)
df = data.frame(t,x,y,z)
p = df %>% ggplot() + geom_point(aes(t, x, text = paste(z)), color = "red") +
geom_point(aes(t, y), color = "blue")
ggplotly(p , tooltip = "z")
当我悬停在点上时,我想显示 z 的值。知道如何在此处执行此操作吗?