Ole*_*Ole 5 plot r ggplot2 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)
理想情况下,注释应位于左下角。
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7711 次 |
| 最近记录: |