【发布时间】:2019-12-31 08:54:05
【问题描述】:
我正在尝试使用facet_wrap 参数在ggplot 中创建图表。
但是,我不希望在每个小图上都有标签,我只希望在图的顶部和左侧有一个标签。
例如在下图中,我想在顶部有标签 SI2、SI1、WS2,在左边有标签 D、E、F。
library(tidyverse)
df <- diamonds %>%
select(cut, color, clarity, price) %>%
filter(clarity %in% c("SI2", "SI1", "VVS2")) %>%
filter(color %in% c("D", "E", "F"))
df %>%
ggplot(aes(cut, price)) +
geom_boxplot() +
facet_wrap(~color + clarity)
【问题讨论】:
-
使用
facet_grid:ggplot(df, aes(cut, price)) + geom_boxplot() + facet_grid(rows = vars(color) , cols = vars(clarity), switch = "y") -
谢谢!将其添加为答案,以便我可以投票。另外,两个问题:1.有没有办法让标签位于 y 轴的左侧? 2. facet_grid 和 facet_wrap 有什么区别?
标签: r ggplot2 facet-wrap