我正在尝试合并用bquote制作的两个表达式。例如:
a = 1
b = 2
x1 = as.expression(bquote(paste("Something ", alpha, " = ", .(a), sep = "")))
x2 = as.expression(bquote(paste("Something else ", beta, " = ", .(b), sep = "")))
有没有办法在不做的情况下执行与x12 = paste(x1, x2, collapse = "some symbol")
类似的操作:
x12 = as.expression(bquote(paste("Something ", alpha, " = ", .(a)," some symbol ",
"Something else ", beta, " = ", .(b), sep = "")))
非常感谢!
答案 0 :(得分:0)
你可以写一个结合了plotmath表达式的小函数:
a = 1
b = 2
x1 = bquote("Something " * alpha == .(a))
x2 = bquote("Something else " * beta == .(b))
comb_plotmath <- function(...) {
Reduce(function(x, y) substitute(x * y, env = list(x = x, y = y)),
list(...))
}
plot.new()
text(0.5, 0.5, comb_plotmath(x1, " some symbol ", x2))
结果:
请注意,plotmath中的paste
没有sep
参数。您可能想要学习help("plotmath")
。