如何更改绘图区域外 geom_text() 中的字体大小?

How to change font size in geom_text() outside plot area?

我想注释一个绘图,并且我希望注释位于绘图区域之外。我找到 this solution 并且它适用于在绘图区域外添加注释,但我无法弄清楚如何更改标签的外观(最重要的是,对于我来说,字体大小)。

这是上述解决方案的一个最小示例:

library (ggplot2)
library(grid)

df=data.frame(y=c("dog1","dog2","dog3"),x=c(12,10,14),n=c(5,15,20))
p <- ggplot(df, aes(x,y)) + geom_point()

# Add the annotation
p <- p + geom_text(aes(label = "Hello World!", x = 0, y = 0), vjust = 2, hjust = 1)

# Code to override clipping
gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid.draw(gt)

理想情况下,注释应位于左下角。

library (ggplot2)
library(grid)

df=data.frame(y=c("dog1","dog2","dog3"),x=c(12,10,14),n=c(5,15,20))
p <- ggplot(df, aes(x,y)) + geom_point()

# Add the annotation
p <- p + geom_text(size=8, colour="red", aes(label = "Hello World!", x = 0, y = 0), vjust = 2.5, hjust = 1)

# Code to override clipping
gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid.draw(gt)