【问题标题】:How to exclude one categorical value in facet wrap ggplot r如何在 facet wrap ggplot r 中排除一个分类值
【发布时间】:2020-06-09 04:22:27
【问题描述】:

我在这里使用 facet_wrap 得到了多个直方图,但不知何故,我在分类变量中仍有“NA”数据用于分面。然后,我将 NA 更改为 0,认为它不会再次出现在情节中。然而,0 是另一个值,例如 NA。

这是代码

ggplot(dftrai,aes(`12 Income`,fill=`13e Toilet type`,color=`13e Toilet type`))+
  geom_histogram(alpha=(0.3))+#psition = identity as overlapping histogram
  theme(legend.position = "top")+
  scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9","#FA3910"))+
  scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9","#FA3910"))+
  facet_wrap(~`13e Toilet type`,ncol = 3)

这是剧情结果 我想摆脱那里的'0'图表 ggplot

【问题讨论】:

  • help("droplevels")

标签: r ggplot2 facet-wrap


【解决方案1】:

一种选择是在管道进入ggplot之前过滤厕所类型不等于0:

library(dplyr)
dftrai %>% 
filter(`13e Toilet type`!="0") %>%  # Filter step here
ggplot(aes(`12 Income`,fill=`13e Toilet type`,color=`13e Toilet type`))+
  geom_histogram(alpha=(0.3))+#psition = identity as overlapping histogram
  theme(legend.position = "top")+
  scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9","#FA3910"))+
  scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9","#FA3910"))+
  facet_wrap(~`13e Toilet type`,ncol = 3)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 2019-08-04
    • 1970-01-01
    相关资源
    最近更新 更多