我正在嘗試傳遞一個變數,該變數toPaste是一個字串,我希望它的一部分被上標。字串:需要上標的"this^2/that^ "位置2和位置。
我四處瀏覽,似乎我需要重新格式化我的字串,然后我可以paste()在一個bquote()例子中,但由于所需的上標嵌入在字串的中間,我不知道如何處理它。下面的示例腳本:
library(ggplot2)
toPaste <- "this^2/that^ "
ggplot() ylab(toPaste)
任何幫助表示贊賞。
uj5u.com熱心網友回復:
您可以使用以下內容:
toPaste <- "this^2/that^' '"
ggplot() ylab(parse(text = toPaste))
請注意,“ ”號需要用單引號括起來。
uj5u.com熱心網友回復:
你可以latex2exp使用 LaTeX 來處理這樣的事情
library(ggplot2)
library(latex2exp)
data("mtcars")
ggplot(mtcars, aes(x = disp, y = mpg))
geom_point()
labs(title = TeX("Title: $\\frac{this^{2}}{\\that^{ }}$"))

由
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482743.html
