Search code examples
rggplot2ggtext

Left align ggplot caption


I'm using the R package ggtext to "plot align" (max left align) my title and subtitle. I also want to use these ggtext methods to "plot align" my caption.

library(tidyverse)
library(ggtext)
ggplot(mpg, aes(cty, hwy)) + 
  geom_point() +
  theme(plot.title.position = "plot",
        plot.caption.position = "plot",
        plot.title = element_markdown(),
        plot.subtitle = element_markdown(),
        plot.caption = element_markdown()) +
  labs(title = "This is the title.", 
       subtitle = "This is the subtitile.", 
       caption = "This is the caption.")

You'll probably notice the caption is right aligned, whereas the title and subtitle are "plot aligned".

right aligned caption

How do I "plot align" my caption?


Solution

  • This works. Based off of @Ben comment.

    library(tidyverse)
    library(ggtext)
    ggplot(mpg, aes(cty, hwy)) + 
      geom_point() +
      theme(plot.title.position = "plot",
            plot.caption.position = "plot",
            plot.title = element_markdown(),
            plot.subtitle = element_markdown(),
            plot.caption = element_markdown(hjust = 0)) +
      labs(title = "This is the title.", 
           subtitle = "This is the subtitile.", 
           caption = "This is the caption.")