英文:
How to show variables not used for plotting in ggplotly on hover?
问题
假设我在使用ggplot绘图时,有一个数据框中的5个变量。我已经使用了其中的3个变量来绘图。当我悬停在散点图上时,我只看到3个变量的信息。
问题:如何在悬停时显示第4个变量,同时显示其他三个变量?
示例示例
使用鸢尾花数据集:
p1 <-
iris %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(alpha=0.5)
ggplotly(p1)
如何在悬停时显示Petal.Length的信息?下面的图像显示了当前的悬停显示情况。
英文:
Suppose I have 5 variables in a data frame used for plotting using ggplot.
I have used 3 out of 5 variables for plotting. When I hover over the scatter plot, I only see 3 variables shown.
Question: How can I show variable 4 along with the other three while hovering?
Sample Example
Using Iris Data set:
p1 <-
iris %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(alpha=0.5)
ggplotly(p1)
How to get Petal.Length info also displayed while hovering?
Image below shows what is currently being shown on hover.
答案1
得分: 1
ggplotly
提供了一个名为"text"的"美学"或属性,可以用于在工具提示中显示附加的数据列:
library(plotly)
iris %>%
ggplot(aes(
x = Sepal.Length, y = Sepal.Width, color = Species,
text = paste0("Petal.Length: ", Petal.Length)
)) +
geom_point(alpha = 0.5)
ggplotly()
英文:
ggplotly
offers a text
"aesthetic" or attribute which could be used to show additional data columns in the tooltip:
library(plotly)
iris %>%
ggplot(aes(
x = Sepal.Length, y = Sepal.Width, color = Species,
text = paste0("Petal.Length: ", Petal.Length)
)) +
geom_point(alpha = 0.5)
ggplotly()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论