How can I use cowplot to add labels to plots in multiplot panels, where the labels have superscripts?
I can use superscripts on the axis titles with substitute
, bquote
or expression
, like this:
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
But I don't know how to give a set of those labels to cowplot to label multiple plots:
# 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
)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : object 'A' not found
What's the secret to getting that to work so I can get something like Ax and Bx as the plot labels instead of A and B in the plot below?
plot_grid(p1, p2,
ncol = 1,
align = "v",
labels = "AUTO"
)
You can do this using a plotmath expression. @user63230 has the right idea in the comments, however, you can't pass the
parse
argument to theplot_grid()
function but you can usedraw_plot_label()
afterwards although you also need to specify the label positions: