居左对齐 ggplot 标题。

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

你可能会注意到标题是与子标题对齐的,而说明文字则是向右对齐的。

right aligned caption

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


2
尝试为 plot_caption 添加 hjust = 0,像这样:plot.caption = element_markdown(hjust = 0) - Ben
2个回答

26

为了让他人更好地阅读,您可以按照以下方式在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.")

左对齐的带标题的图表


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接