使用 ggplotly() 显示绘图时,绘图字幕丢失
Posted
技术标签:
【中文标题】使用 ggplotly() 显示绘图时,绘图字幕丢失【英文标题】:Plot subtitle is lost when plot is diplayed with ggplotly() 【发布时间】:2021-11-03 11:47:44 【问题描述】:我用标题和副标题创建了下面的 ggplot,但是当我使用 ggplotly()
显示它时,副标题丢失了。
library(ggplot2)
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot()
library(plotly)
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
subtitle = "Plot of length by dose",
caption = "Data source: ToothGrowth")
ggplotly(p)
【问题讨论】:
【参考方案1】:library(ggplot2)
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot()
library(plotly)
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
subtitle = "Plot of length by dose",
caption = "Data source: ToothGrowth")
ggplotly(p)%>%
layout(title = list(text = paste0('Effect of Vitamin C on Tooth Growth"',
'<br>',
'<sup>',
'Plot of length by dose','</sup>')))
如果它解决了您的问题,请告诉我
【讨论】:
以上是关于使用 ggplotly() 显示绘图时,绘图字幕丢失的主要内容,如果未能解决你的问题,请参考以下文章