如何在 facet wrap ggplot r 中排除一个分类值
How to exclude one categorical value in facet wrap ggplot r
我在这里使用 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
一个选项是在管道进入 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)
我在这里使用 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
一个选项是在管道进入 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)