我正在尝试使用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);