减少上标字体大小 ggplot2 R

问题描述

我正在开发一个带有 ggplot2 和包 ggtext 的脚本,以生成一些在标题旁边带有上标的图,这些图在参考表中进一步分组。

我正在做的一个简单的例子是:

library(ggplot2)
library(ggtext)

ggplot() +
geom_blank() +
labs(title = "The title of the plot^21") +
theme_void() +
theme(plot.title = element_markdown(size = 20,hjust = 0.5))

但是因为我需要在我的项目中使用大字体,所以上标字体太大了。有没有办法在保持相同文本大小的同时减少它?提前致谢。

解决方法

也许这会有所帮助:

library(ggplot2)
library(ggtext)
#Code
ggplot() +
  geom_blank() +
  labs(title = "The title of the plot<span style='font-size:20pt;
       color:black'><sup>2</sup></span>") +
  theme_void() +
  theme(plot.title = element_markdown(size = 25,hjust = 0.5))

输出:

enter image description here

,

后来我发现我们可以在代码中使用双克拉,这也回答了我的问题:

labs(title = "The title of the plot^^21")