facet_grid
允许我根据y轴上的项目数量(space
参数)调整每个小面板的宽度:
df <- data.frame(label = c("Variable one", rep("Variable two", 2), rep("Variable three", 3)), item = c("A", "B", "C", "D", "E", "F"), value = rnorm(6))
ggplot(df, aes(x = value, y = item)) +
geom_point() +
facet_grid(label ~ ., scales = "free_y", space = "free_y") +
ylab("") +
theme(strip.text.y = element_text(angle=0))
但是我希望在顶部显示facet标签,因此我切换到facet_wrap
,并且失去了space
参数(facets具有相同的宽度):
ggplot(df, aes(x = value, y = item)) +
geom_point() +
facet_wrap(~ label, scales = "free_y", ncol = 1) +
ylab("")
能否兼得两全?
提前感谢您的帮助。
labs(y = NULL)
来删除标签标题,这样实际上将不会绘制任何内容。否则,那里仍然会有"某些东西"存在。+1 - tjeboggforce::facet_col(facets = vars(label), scales = "free", space = "free") + scale_x_continuous(breaks = seq(-1, 1, 1), limits = c(-1, 1))
- John-Henry