【问题标题】:ggplot: how to remove unused factor levels from a facet?ggplot:如何从一个方面删除未使用的因子水平?
【发布时间】:2019-11-23 09:41:43
【问题描述】:

以下代码

d1 = data.frame(y=1:2,group=factor(c('A','B'), levels=c('A','B','C')), fac = 'f1')
d2 = data.frame(y=1:3,group=factor(c('A','B','C'), levels=c('A','B','C')), fac = 'f2')
d = rbind(d1,d2)

library(ggplot2)
ggplot( d, aes(x=group, y=y) ) + geom_point(size=3) + facet_grid( ~ fac)

结果如下图。如何从构面“f1”中删除未使用的因子级别C

【问题讨论】:

    标签: ggplot2 facet


    【解决方案1】:

    在构面网格中设置 scales = free 即可:

    facet_grid( ~ fac, scales = "free")
    
    

    【讨论】:

    • 谢谢,知道了就这么简单。
    猜你喜欢
    • 1970-01-01
    • 2012-07-09
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    相关资源
    最近更新 更多