具有两个fontsize的单行ggplot2标题

问题描述 投票:0回答:1

我想强调以下情节标题中的数字:

library(ggrepel)
library(ggplot2)

dat <- subset(mtcars, wt > 2.75 & wt < 3.45)
dat$car <- rownames(dat)

p <- ggplot(dat, aes(wt, mpg, label = car)) +
  geom_point(aes(color=car))+ 
  geom_label_repel(aes( fill=car), show.legend  = F) +

  labs(title = "numbers 1234 another thing")
p

如果我只能获得具有不同字体大小的数字,那就太好了。谢谢

r ggplot2
1个回答
0
投票

一个选项是使用ggtext(需要ggplot2 >= 3.3.0

library(ggplot2)
library(ggtext)
library(ggrepel)
ggplot(dat, aes(wt, mpg, label = car)) +
    geom_point(aes(color=car))+
    geom_label_repel(aes(fill = car), show.legend  = F) +
    ggtitle("numbers <span style='font-size:80pt'>1234</span> another thing") +
    theme(plot.title = element_markdown())

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.