facet_wrap 每个子图中具有不同的因子水平
facet_wrap with different factor levels in each subplot
是否有可能使用 facet_wrap
从第一个子图中删除 "f e d" 级别并从第二个子图中删除 "c b a" 级别?换句话说,我想在第一个子图中只有 "c b a" 列,而在第二个子图中只有 "f e d" 列。
示例data.frame:
df <- data.frame(x = letters[1:6], gr = c(rep("kk", 3), rep("yy", 3)), v = 10:15)
剧情调用:
ggplot(data = df, aes(x = x, y = v)) +
geom_col() +
coord_flip() +
facet_wrap(~gr, nrow = 2)
要避免 y 轴的固定比例,只需将 scales = "free_y"
添加到 facet_wrap()
命令即可。
ggplot(data = df, aes(x = x, y = v)) +
geom_col() +
coord_flip() +
facet_wrap(~gr, nrow = 2, scales = "free_y")
是否有可能使用 facet_wrap
从第一个子图中删除 "f e d" 级别并从第二个子图中删除 "c b a" 级别?换句话说,我想在第一个子图中只有 "c b a" 列,而在第二个子图中只有 "f e d" 列。
示例data.frame:
df <- data.frame(x = letters[1:6], gr = c(rep("kk", 3), rep("yy", 3)), v = 10:15)
剧情调用:
ggplot(data = df, aes(x = x, y = v)) +
geom_col() +
coord_flip() +
facet_wrap(~gr, nrow = 2)
要避免 y 轴的固定比例,只需将 scales = "free_y"
添加到 facet_wrap()
命令即可。
ggplot(data = df, aes(x = x, y = v)) +
geom_col() +
coord_flip() +
facet_wrap(~gr, nrow = 2, scales = "free_y")