隐藏绘图工具提示颜色痕迹

Hiding plotly tooltip color traces

有没有办法隐藏 ggplot 图表上的工具提示颜色痕迹,该图表已通过 plotly 进行交互?在下面的示例中,我希望我的工具提示从此开始:

为此:

library(plotly)
library(tidyverse)

## fake data
dat <- data.frame(date = seq(as.Date("1910/1/1"), as.Date("1910/1/10"), "days"),
                  pred = 1:10,
                  pred2 = 31:40,
                  ci_low = seq(0, 9, 1),
                  ci_upper = seq(2, 11, 1))

## plot
p1 <- dat %>% 
  ggplot(aes(x = date, y = pred)) +
  geom_line(color = "red", aes(group = 1, text = paste("date:", date, "\npred:", pred, "\npred2:", pred2, "\nci_low:",  ci_low, "\nci_upper:", ci_upper))) +
  geom_line(aes(group = 1, x = date, y = pred2), color = "green") +
  geom_ribbon(aes(group = 1, x = date, ymin = ci_low, ymax = ci_upper), alpha = 0.2, linetype = 0)

## plotly-fy
ggplotly(p1, tooltip = c("text")) %>%
  layout(hovermode = "x unified") %>%
  style(hoverinfo = "skip", traces = 2)

希望有更好的方法,但这里有一个使用隐藏跟踪的解决方法:

library(plotly)
# library(tidyverse)

## fake data
dat <- data.frame(date = seq(as.Date("1910/1/1"), as.Date("1910/1/10"), "days"),
                  pred = 1:10,
                  pred2 = 31:40,
                  ci_low = seq(0, 9, 1),
                  ci_upper = seq(2, 11, 1))

## plot
p1 <- dat %>% 
  ggplot(aes(x = date, y = pred)) +
  geom_point(color = NA, aes(group = 1, text = paste("date:", date, "\npred:", pred, "\npred2:", pred2, "\nci_low:",  ci_low, "\nci_upper:", ci_upper))) +
  geom_line(aes(group = 1, x = date, y = pred), color = "red") +
  geom_line(aes(group = 1, x = date, y = pred2), color = "green") +
  geom_ribbon(aes(group = 1, x = date, ymin = ci_low, ymax = ci_upper), alpha = 0.2, linetype = 0)

## plotly-fy
ggplotly(p1, tooltip = c("text")) %>%
  layout(hovermode = "x unified") %>%
  style(hoverinfo = "skip", traces = c(2:4))