如何使用cowplot向多图面板中的图添加标签,其中标签具有上标?
我可以通过 substitute
、bquote
或 expression
在轴标题上使用上标,如下所示:
library(ggplot2)
library(cowplot)
p1 <- ggplot(mtcars, aes(disp, mpg)) +
geom_point()
p2 <- ggplot(mtcars, aes(disp, hp)) +
geom_point() +
# this will create a nice superscript
xlab(bquote(A^x))
p2
但我不知道如何为cowplot提供一组标签来标记多个图:
# create a vector of labels for the grid of plots
labels_with_superscript <-
c(bquote(A^x),
bquote(B^x))
# create the grid of plots?
plot_grid(p1, p2,
ncol = 1,
align = "v",
labels = labels_with_superscript
)
(function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : 未找到对象“A”
让它发挥作用的秘诀是什么,这样我就可以得到像 Ax 和 Bx 这样的东西作为绘图标签,而不是下图中的 A 和 B?
plot_grid(p1, p2,
ncol = 1,
align = "v",
labels = "AUTO"
)
最佳答案
您可以使用绘图数学表达式来完成此操作。 @user63230 在评论中有正确的想法,但是,您无法将 parse
参数传递给 plot_grid()
函数,但您可以使用 draw_plot_label()
之后,尽管您还需要指定标签位置:
library(ggplot2)
library(cowplot)
labels_with_superscript <- c("A^x", "B^x")
plot_grid(p1, p2,
ncol = 1,
align = "v") +
draw_plot_label(labels_with_superscript, x = c(0, 0), y = c(1, .5), parse = TRUE)
关于r - 如何在cowplot多面板图标签中使用上标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65086663/