[英]Store plotly tooltip information outside of ggplot object
是否可以在 ggplot object 之外存储 plotly 工具提示信息? 例如,我想从这个 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")
对此:
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")
使用quote
和bang-bang 运算符!!
取消报价:
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.