I can use bquote to write plot titles with a mix of math symbols and variable values in them
p1 <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
avg_disp <- mean(mtcars$disp)
p1+labs(title = bquote(AVG[disp]==.(avg_disp)))

However the same is not possible when arranging plots and putting a figure title with plot_annotation()
p1 <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
p2 <- ggplot(mtcars, aes(gear, mpg)) + geom_boxplot()
avg_disp <- mean(mtcars$disp)
p1 + p2 + plot_annotation(title = bquote(AVG[disp]==.(avg_disp)))
which produces the following error message:
Error in dots_list(..., title = title, subtitle = subtitle, caption = caption, :
object 'AVG' not found
In addition: Warning message:
Continuous x aesthetic -- did you forget aes(group=...)?
The documentation of plot_annotation does say that title, subtitle and caption should be text strings, so I wouldn't say this is a bug. I'm just curious about what would be a workaround?
Thanks in advance
I can use
bquoteto write plot titles with a mix of math symbols and variable values in themHowever the same is not possible when arranging plots and putting a figure title with
plot_annotation()which produces the following error message:
The documentation of
plot_annotationdoes say that title, subtitle and caption should be text strings, so I wouldn't say this is a bug. I'm just curious about what would be a workaround?Thanks in advance