我有一个新手问题:对于这段代码,我想把VT1
的1
作为下标。
[...]
annotate("text", x=VT1PPO_CAD-2, y=40, ##or bp_CAD if we use absVO2%
label=paste0("VT1: ", round(VT1PPO_CAD, 0), "%"), angle=90, size = 4) +
[...]
我试过了,但它不起作用。
label=paste0(expression(paste("V", T[1], ": ")), round(VT1PPO_CAD, 0), "%")
非常感谢!
2条答案
按热度按时间vuktfyat1#
你尝试的解决方案的根本问题是,如果你想让R正确地格式化你的 entire 标签,它必须是一个未求值的表达式。你的代码试图将未求值的表达式作为字符串的一部分使用(外部的
paste0
调用将参数转换为字符串)。这是行不通的。因此,您需要将逻辑颠倒过来:你需要创建一个未赋值的表达式,并且你需要将变量(
VT1PPO_CAD
)* 插入到 * 那个表达式中(舍入后)。expression
函数不允许插入值1。要插入(= insert evaluated)子表达式,您需要使用其他解决方案。存在几种解决方案,但我最喜欢的方法是bquote
函数。此外,不需要拆分和/或引用
V
和T
;把它们放在一起:bquote
接受表达式,并在将求值结果插入到周围的表达式之前,计算 Package 在.(…)
中的子表达式。1一般来说
expression
函数是完全无用的,我甚至不知道它为什么存在;据我所知,它对于quote
是100%冗余的,答案可能是“for compatibility with S”。evrscar22#
我们可以使用
substitute
:或
ggplot2
(根据您的标签):