修改通过ggplotly创建的图的工具提示信息 [英] Modify tooltip info of a plotly graph created via ggplotly
问题描述
运行了自己的聚类算法后,我有了这个数据集以及它们各自的x和y,我想要一种使用交互式视图对其进行分析的方法.
I have this dataset and their respective x and y after I ran my own clustering algorithm and I want a way to analyze it with an interactive view.
value max_value Var1 x y
3 6 potato 4 2
4 4 banana 3 2
5 6 apple 3 1
value max_value Var1 x y
3 6 potato 4 2
4 4 banana 3 2
5 6 apple 3 1
我正在尝试使用plotly,我想让plotly查看器仅向我显示相应点的工具提示/鼠标悬停信息上的值和max_value.这是我到目前为止的内容:
I'm trying to use plotly and I'd like to have the plotly viewer show me only the value and max_value on the tooltip/hoverinfo of the respective point. This is what I have so far:
gg <- ggplot(test) +
geom_point(aes(x = x,y = y, color = Var1), size = 4, alpha = 0.5)
ggplotly(gg)
#alternative
plot_ly(df, x = ~x, y = ~y, color = ~Var1)
是否可以更改该图在工具提示或其他程序包中显示的值,这可以帮助我解决此问题?
Is there a way to change the values that the plot show on the tooltip or another package that could help me in this?
推荐答案
您可以添加text
美学的一些工具提示信息:
You can add some tooltip info with the text
aesthetic:
library(plotly)
gg <- ggplot(test) +
geom_point(aes(x = x, y = y, color = Var1,
text = paste0("Value: ", value, "</br>Max: ", max_value)),
size = 4, alpha = 0.5)
ggplotly(gg)
如果只需要value
和max_value
:
gg <- ggplot(test) +
geom_point(aes(x = x, y = y, color = Var1,
text = paste0("Value: ", value, "</br></br>Max: ", max_value)),
size = 4, alpha = 0.5)
ggplotly(gg, tooltip = "text")
这篇关于修改通过ggplotly创建的图的工具提示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!