首页 > 解决方案 > 使用 tooltip="text' 选项时如何显示拟合线文本?

问题描述

问题: 当我使用 tooltip="text" 时,适合的蓝线的文本消失了。我希望能够在数据点上显示自定义文本并让文本出现在蓝线上,而不仅仅是置信区间(灰色区域)。

图像,CI 显示但不显示蓝线文本 在此处输入图像描述

代码:

library("plotly")
library("ggplot2")

p <- ggplot(mtcars, aes(wt, mpg, text = row.names(mtcars))) + 
  geom_point() + geom_smooth(method="lm", aes(x=mtcars$wt, y=mtcars$mpg), formula=y~poly(x,2), inherit.aes=FALSE)

ggplotly(p +geom_smooth(se=FALSE), tooltip="text")

标签: rggplot2ggplotly

解决方案


推荐阅读