facet_wrap()
因没有space = "free"
争论而被认可(https://github.com/tidyverse/ggplot2/issues/2933)。这可能会导致绘图 y 轴上的间距问题。
使用以下代码创建上图:
library(tidyverse)
p <-
mtcars %>%
rownames_to_column() %>%
ggplot(aes(x = disp, y = rowname)) + geom_point() +
facet_wrap(~ carb, ncol = 1, scales = "free_y")
facet_grid
另一方面有space = "free"
论据。允许良好的 y 轴间距。
使用以下代码创建上图:
p <-
mtcars %>%
rownames_to_column() %>%
ggplot(aes(x = disp, y = rowname)) + geom_point() +
facet_grid(carb ~ ., scales = "free_y", space = "free_y")
问题在于标签在侧面,而不是顶部。有时我的构面标签较长,而构面中的行数很少。这意味着刻面标签被切断。
ggforce包中有一个解决方案(ilarischeinin 在https://github.com/tidyverse/ggplot2/issues/2933上发表评论)。
p <-
mtcars %>%
rownames_to_column() %>%
ggplot(aes(x = disp, y = rowname)) + geom_point()
p + ggforce::facet_col(vars(carb), scales = "free_y", space = "free")
但是,离开ggplot2有一些限制。例如,我最终想要一个两列图,而ggforce似乎无法实现此功能。有什么方法可以产生相同的结果,facet_wrap()
以便我可以利用这个ncol()
论点?