0

我正在使用 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.")

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

右对齐标题

我如何“情节对齐”我的标题?

4

2 回答 2

7

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

带有标题左对齐的绘图

于 2021-04-03T21:58:57.203 回答
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.")
于 2020-11-06T21:08:53.983 回答