左对齐ggplot标题

问题描述

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

data %>% 
  group_by(group) %>% 
  nest() %>% 
  mutate(v=map(data,~rep_sample_n(.,size=10,replace=FALSE,reps=20))) %>% 
  unnest(v)

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

right aligned caption

如何“图解对齐”我的标题

解决方法

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

let $this = $(this);
let showing = $this.hasClass('typso-showing');
$tips.tipso('hide')  // close all,prevent two showing

plot with caption left aligned

,

这有效。基于@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.")