左对齐ggplot标题

Jas*_*ter 0 r ggplot2 ggtext

我正在使用 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.")
Run Code Online (Sandbox Code Playgroud)

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

右对齐标题

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

小智 5

为了他人的利益,您可以通过以下方式左对齐 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.")
Run Code Online (Sandbox Code Playgroud)

标题左对齐的绘图


Jas*_*ter 1

这有效。基于@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.")
Run Code Online (Sandbox Code Playgroud)