This is similar question to this one How to use superscript with ggplot2
but instead of hard coded value of the label I have a string in variable and I need to append the "mm^3" to the string and display that in ggplot
.
I have code like this:
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"))
}
I've tried to use this:
paste(ylab, bquote(~mm^3))
but this give me vector with 2 elements:
[1] "foo ~" "foo mm^3"