左对齐 ggplot 标题

Left align ggplot caption

我正在使用 R 包 ggtext 来“绘制对齐”(最大左对齐)我的标题和副标题。我还想使用这些 ggtext 方法来“绘制对齐”我的标题。

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

您可能会注意到标题是右对齐的,而标题和副标题是“情节对齐”的。

如何“绘制对齐”我的标题?

这行得通。基于@Ben 评论。

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

为了其他人的利益,您可以通过以下方式左对齐ggplot2中的标题:

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