如何在ggplotly中为geom_segment添加工具提示?

时间:2020-04-04 16:19:00

标签: r ggplot2 r-plotly ggplotly

我正在尝试使用ggplotly制作交互式图表。我希望工具提示在将鼠标悬停在点上时显示点的坐标(这很容易),而在将鼠标悬停在线上时显示描述(列)(此处需要帮助)。

我考虑过在线上放置一个不可见点,但是由于y轴上的因素(不是整数)而失败了。 最糟糕的情况是,如果可以解决问题,我愿意将代码从ggplot移至plotly之类的东西。

d = data.frame(
  x1=c(2,3),
  y1=c("A","B"),
  x2=c(3,5),
  y2=c("B","C"),
  decription=c("abc","xyz"))


g =ggplot(d,aes(x=x1,y=y1))+geom_point()+geom_point(aes(x2,y2)) +
  geom_segment(aes(xend=x2,yend=y2))
#This creates the plot correctly but no interactivity on the line.

#plotting the graph
ggplotly(g);

0 个答案:

没有答案
相关问题