合并表达式以进行绘图
Merging expressions for plotting
我正在尝试合并两个用 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 = "")))
非常感谢!
您可以编写一个组合 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")
.
我正在尝试合并两个用 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 = "")))
非常感谢!
您可以编写一个组合 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")
.