5

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?

Display name
  • 4,153
  • 5
  • 27
  • 75
  • 2
    Try adding `hjust = 0` for `plot_caption` like this: `plot.caption = element_markdown(hjust = 0)` – Ben Nov 06 '20 at 02:40

2 Answers2

25

For the benefit of others, you can left align the caption in ggplot2 in the following way:

library(ggplot2)

ggplot(mpg, aes(cty, hwy)) + 
  geom_point() +
  theme(plot.caption = element_text(hjust = 0)) + # set the left align here
  labs(title = "This is the title.", 
       subtitle = "This is the subtitile.", 
       caption = "This is the caption.")

plot with caption left aligned

Marcos
  • 444
  • 4
  • 9
1

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.")
Display name
  • 4,153
  • 5
  • 27
  • 75