Skip to content

bquote support in plot_annotation? #295

Description

@almenal

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)))

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions