如何在facet wrap ggplot r中排除一个分类值

问题描述 投票:0回答:1

我在这里使用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'图表

“

r ggplot2 facet-wrap
1个回答
0
投票

一种选择是在管道输送到ggplot之前过滤厕所类型不等于零:

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)
© www.soinside.com 2019 - 2024. All rights reserved.