【发布时间】:2017-10-19 11:43:57
【问题描述】:
这与How to use superscript with ggplot2的问题类似
但我在变量中有一个字符串,而不是标签的硬编码值,我需要将“mm^3”附加到字符串并在ggplot中显示。
我有这样的代码:
genericPlot <- genericPlot + labs(y = wrap(ylab, wrap.length))
#' Wrap
#'
#' @param x character, values to be wrapped
#' @param width numeric, max number of characters
#'
#' @return Wrapped x
wrap <- function(x, width) {
sapply(
X = x,
FUN = function(x) paste(strwrap(x, width = width), collapse = "\n"))
}
我试过用这个:
paste(ylab, bquote(~mm^3))
但这给了我带有 2 个元素的向量:
[1] "foo ~" "foo mm^3"
【问题讨论】:
-
你能举一个可重现的小例子来演示这个附加吗?
-
我第二个@RomanLuštrik 评论(并品脱到
help('plotmath')或/和tidyverse's Plotmath page on github)。