[英]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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.