如何手動設定圖中點的標簽?
library(ggplot2)
library(plotly)
p <- iris %>%
ggplot(aes(Sepal.Length, Sepal.Width, color = Species))
geom_point()
labs(
title = "A graph",
x = "Sepal Length (cm)",
y = "Sepal Width (cm)",
color = "Species of Iris"
)
ggplotly(p)
軸已正確標記,但資料未正確標記。

這是它在 Python 中如何作業的示例

uj5u.com熱心網友回復:
這是一個使用textggplot 不使用的美學的示例,但它被傳遞給plotly,并glue::glue作為paste0.
library(ggplot2)
library(plotly)
p <- iris %>%
ggplot(aes(Sepal.Length, Sepal.Width, color = Species))
geom_point(aes(text = glue::glue(
"Species of iris={Species}\n",
"Sepal Width (cm)={Sepal.Width}")))
# alternative using base paste0:
#geom_point(aes(text = paste0("Species of iris=", Species, "\n",
# "Sepal Width (cm)=", Sepal.Width)))
labs(
title = "A graph",
x = "Sepal Length (cm)",
y = "Sepal Width (cm)",
color = "Species of Iris"
)
ggplotly(p, tooltip = 'text')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/493126.html
