[英]Store plotly tooltip information outside of ggplot object
Is it possible to store plotly tooltip information outside of a ggplot object?是否可以在 ggplot object 之外存储 plotly 工具提示信息? For example, I would like to go from this:
例如,我想从这个 go :
library(tidyverse)
library(plotly)
p1 <- mtcars %>%
ggplot(aes(x = mpg, y = hp, text = paste0("<b>MPG: </b>", mpg, "<br>",
"<b>HP: </b>", hp))) +
geom_point()
ggplotly(p1, tooltip = "text")
To this:对此:
tooltip_text <- paste0("<b>MPG: </b>", mpg, "<br>",
"<b>HP: </b>", hp)
p1 <- mtcars %>%
ggplot(aes(x = mpg, y = hp, text = tooltip_text)) +
geom_point()
ggplotly(p1, tooltip = "text")
Using quote
and the bang-bang operator !!
使用
quote
和bang-bang 运算符!!
to unquote:取消报价:
tooltip_text <- quote(paste0("<b>MPG: </b>", mpg, "<br>",
"<b>HP: </b>", hp))
p1 <- mtcars %>%
ggplot(aes(x = mpg, y = hp, text = !! tooltip_text)) +
geom_point()
ggplotly(p1, tooltip = "text")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.