添加标记并在R中显示工具提示

添加标记并在R中显示工具提示,r,ggplot2,hover,plotly,R,Ggplot2,Hover,Plotly,下面的R代码创建带有标记的线图。我希望创建一个绘图,这样当在标记上执行悬停时,它会在工具提示中给出“digits”和“sepw”值。标记也应该是粗体的。请帮忙 digits = 1:150 sep = iris$Sepal.Length sepw = iris$Sepal.Width plot_f1 <- ggplot(iris, aes(x = digits)) + geom_line(aes(y = sep, color = "red", label = sepw ))

下面的R代码创建带有标记的线图。我希望创建一个绘图,这样当在标记上执行悬停时,它会在工具提示中给出“digits”和“sepw”值。标记也应该是粗体的。请帮忙

 digits = 1:150
 sep = iris$Sepal.Length
 sepw = iris$Sepal.Width
 plot_f1 <-  ggplot(iris, aes(x = digits)) + 
 geom_line(aes(y = sep, color = "red", label = sepw )) + geom_point(y = sep)
 plot_f1 = ggplotly(plot_f1)
 plot_f1
位数=1:150
sep=虹膜$萼片长度
sepw=虹膜$萼片宽度

plot_f1这是您问题的第一个解决方案:

library(ggplot2)
library(plotly)

digits = 1:150
sep = iris$Sepal.Length
sepw = iris$Sepal.Width
plot_f1 <-  ggplot(iris, aes(x=digits, y=sep, label=sepw)) + 
            geom_line(color="red") + geom_point()
plot_f1 <- ggplotly(plot_f1, tooltip=c("x","label"))
plot_f1

您可以只查看
ggplotly(plot\u f1,tooltip=c(“x”,“label”))
就可以了
plot_f2 <-  ggplot(data=iris, aes(x=digits, y=sep, group=1, 
                   text=paste("Sepw =",sepw,"<br />Digits =",digits))) + 
            geom_line(color="red") + geom_point()
plot_f2 <- ggplotly(plot_f2, tooltip="text")
plot_f2