【发布时间】:2020-10-13 20:24:12
【问题描述】:
在facet_grid 中添加分面标题是否有规范的方法?或者facet_wrap 中特定行标签的方法? (没有geom_text、geom_label 或 grob 操作。)
考虑:
dat <- data.frame(rowInd = paste0("R", c(1, 2, 2, 3, 3, 3)), colInd = paste0("C", c(1, 1, 2, 1, 2, 3)),
facetName = c("1-10", "60-70", "80-90", "100-110", "120-130", "140-150"), val=1:6)
dat
# rowInd colInd facetName val
# 1 R1 C1 1-10 1
# 2 R2 C1 60-70 2
# 3 R2 C2 80-90 3
# 4 R3 C1 100-110 4
# 5 R3 C2 120-130 5
# 6 R3 C3 140-150 6
直接地块给出:
library(ggplot2)
ggplot(dat, aes(x=1, y=val)) + facet_grid(rowInd ~ facetName, switch="y") # 1
ggplot(dat, aes(x=1, y=val)) + facet_wrap(rowInd ~ facetName) # 2
ggplot(dat, aes(x=1, y=val)) + facet_grid(rowInd ~ colInd, switch="y") # 3
地点:
- 包括我想要的行和分面标签,但并非所有分面标签都适用于所有行;
- 正确地将行标签 (
"R1") 与构面标签相关联,每个构面一个标签,但失去构面之间的行从属关系; - 丢失分面标签。
如果需要,我可以“填写”数据(也许是为了便于绘制正确的图),尽管让它们自动空心图或空白空间会很棒。
【问题讨论】:
-
可能最简单的创建右侧图的方法是合并 3 个图,每行 1 个。
-
是的,对不起,这也是我试图避免的事情,但这也是一种选择。谢谢,@Axeman。
标签: r ggplot2 facet facet-wrap facet-grid