使用 R 中的“bquote()”和“str2lang()”函数用百分号标记“plot()”轴

Labeling a 'plot()' Axis With a Percent Sign Using the 'bquote()' and 'str2lang()' Functions in R

提问人:David Moore 提问时间:10/10/2023 更新时间:10/10/2023 访问量:24

问:

我有以下情节。

plot(0, xlab = '', ylab = '')

出于我不打算花时间在这里解释的原因,我必须使用 和 函数来标记水平轴和垂直轴。这是我到目前为止尝试过的。bquote()str2lang()

Labels <- c('cm^2~hr^-1', '%')
mtext(bquote(.(str2lang(Labels[1]))), side = 1)
mtext(bquote(.(str2lang(Labels[2]))), side = 2)

为什么符号在这里不起作用?有解决方法吗?谢谢!'%'

r 绘制 轴标签

评论


答:

3赞 stefan 10/10/2023 #1

如果要打印文字百分号,则必须将其引用为“特殊”字符:%?plotmath

plot(0, xlab = '', ylab = '')

Labels <- c('cm^2~hr^-1', '"%"')
mtext(bquote(.(str2lang(Labels[1]))), side = 1, line = 3)
mtext(bquote(.(str2lang(Labels[2]))), side = 2, line = 3)