小编Ole*_*Ole的帖子

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

我想对绘图进行注释,并且希望注释位于绘图区域之外。我找到了这个解决方案,它适用于在绘图区域之外添加注释,但我无法弄清楚如何更改标签的外观(最重要的是,就我的目的而言,字体大小)。

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

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)
Run Code Online (Sandbox Code Playgroud)

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

plot r ggplot2 geom-text

5
推荐指数
1
解决办法
7711
查看次数

标签 统计

geom-text ×1

ggplot2 ×1

plot ×1

r ×1