首页 > 解决方案 > ggplot2:更改 annotation_custom() 的字体大小

问题描述

我使用 annotation_custom() 在我的情节下方添加文本。但是,我无法弄清楚如何减小字体大小。绝望地,我尝试geom_text(size= 8)了哪个不起作用annotation_custom(size=8)并且不采用“大小”参数。如何更改 annotation_custom() 的字体大小?

df <- data.frame(x=seq(1:100), y=sort(rexp(100, 2)))
p= ggplot(df, aes(x=x, y=y)) + 
   geom_point()+
   theme(plot.margin = unit(c(1,1,3,1), "cm"))+
   ggtitle('Random Plot')

Text1 = textGrob('Additional suggestions:')
p1 = p + annotation_custom(grob = Text1,  xmin = 0.2, xmax = 0.2, ymin = -0.3, ymax = -0.3)

gt <- ggplotGrob(p1)
gt$layout$clip[gt$layout$name=="panel"] <- "off"
grid.newpage()
grid.draw(gt)

任何信息都会非常有帮助,非常感谢!

标签: rggplot2

解决方案


推荐阅读