我只是想为ggplot2生成的每个数字面板添加注释; (a),(b),(c)等简单的标签。有没有简单的方法来做到这一点?ggplot2:geom_text()with facet_grid()?
回答
来源:https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/RL8M7Ut5EpU您可以使用以下方法:
library(ggplot2)
x <-runif(9, 0, 125)
data <- as.data.frame(x)
data$y <- runif(9, 0, 125)
data$yy <- factor(c("a","b","c"))
ggplot(data, aes(x, y)) +
geom_point(shape = 2) +
facet_grid(~yy) +
geom_text(aes(x, y, label=lab),
data=data.frame(x=60, y=Inf, lab=c("this","is","the way"),
yy=letters[1:3]), vjust=1)
这应该给你:
+1,但是你能否提供更多的上下文来了解它的工作原理?现在它只是一段代码和一张图片。 – 2013-04-07 20:30:09
当然。基础'ggplot'调用具有数据框和'geom_point''facet_grid'构面的实际绘图数据。关键是为'geom_text'设置一个新的数据框(在代码片段中动态创建,但可以在'ggplot'块外部创建并引用数据框),并将标签元素的数量与方面的数量。您可以对'geom_text'使用多次调用,以在各个构面之间放置多个不同的标签。他们会被依次引用,所以要注意这一点。 – hrbrmstr 2013-04-07 20:53:12
如果您想要绘制多个标签,则不需要多次调用geom_text,只需将行添加到具有适当文本和facet_grid变量的data.frame。 – 2013-04-07 21:06:20
基本上,您将创建一个data.frame
,其中包含带文本的列的文本以及包含用于facet_grid
的变量的列。然后,您可以简单地将geom_text
与data.frame
相加。请参阅geom_text
的文档以获取关于文本放置等的更多详细信息。
- 1. ggplot2 coord_flip()with geom_text
- 2. ggplot2:geom_violin(),geom_text()with facet_grid()打印每个因子中的总行数,不包括NA
- 3. 使用ggplot2在ggplot2中的多个facet_grid中的良好geom_text质量
- 4. GGplot2的最小尺寸geom_text()
- 5. ggplot2 dotplot with facet_grid with top ala facet_wrap(但是w/space =“free_x”)?
- 6. 盒装geom_text与ggplot2
- 7. [R GGPLOT2 facet_grid问题
- 8. ggplot2,facet_grid,自由秤?
- 9. 错误与GGPLOT2 facet_grid
- 10. R ggplot2箭头与geom_text
- 11. 对齐geom_text到geom_vline在GGPLOT2
- 12. ggplot2 facet_grid排列面板
- 13. ggplot2柱状图与facet_grid
- 14. R - ggplot2:geom_text的位置不起作用
- 15. ggplot2 facet_wrap geom_text不接受日期值
- 16. 使用ggplot2左对齐geom_text图层
- 17. ggplot2中的geom_text()大小定义
- 18. ggplot2中geom_text的相对位置?
- 19. ggplot2-geom_linerange with stat_smooth
- 20. facet_grid ggplot2 panel.margin显示不正确?
- 21. ggplot2 drop = FALSE与facet_grid不一致
- 22. 在facet_grid(ggplot2)中包装一个维度
- 23. GGPLOT2:改变strip.text位置facet_grid情节
- 24. ggplot2:geom_pointrange()facet_grid()与coord_flip()和自由标度
- 25. 如何在ggplot2中正确使用facet_grid?
- 26. R/GGPLOT2 - 上facet_grid重叠标签
- 27. 旋转开关小标签在GGPLOT2 facet_grid
- 28. ggplot2 facet_grid()更改背景颜色
- 29. 在ggplot2中自定义facet_grid中的ymax
- 30. R ggplot2 facet_grid规模和空间
你有一个图片作为一个例子,你可以发布? – 2013-04-07 20:14:22
对不起,我需要弄清楚如何发布图片... – hatmatrix 2013-04-07 22:02:29