我们能在正在发生的阴谋中消除NA吗。我试过使用na.rm,但它不起作用

我们能在正在发生的阴谋中消除NA吗。我试过使用na.rm,但它不起作用,r,ggplot2,R,Ggplot2,我有一个数据帧df,但在值列中有NA p12 Var1 ColA ColB 1 A NA 44.7 2 asgfg 2.1 NA 3 B NA 55.3 4 dds 2.1 NA 5 dfg 4.3 NA 6 dfh 2.1 NA 7 dgh 2.1 NA 8 dghgd 2.1 NA 9 dgrert 2.1 NA 所以我策划 ggplot(data=p12,aes(

我有一个数据帧df,但在值列中有NA

p12
     Var1 ColA ColB
1       A   NA 44.7
2   asgfg  2.1   NA
3       B   NA 55.3
4     dds  2.1   NA
5     dfg  4.3   NA
6     dfh  2.1   NA
7     dgh  2.1   NA
8   dghgd  2.1   NA
9  dgrert  2.1   NA
所以我策划

ggplot(data=p12,aes(x=Var1,y=ColB,fill=Var1))+geom_bar(stat = "identity")+coord_flip()

它甚至还将NA考虑在内。是否有办法消除这种情况

尽管可能过于具体,
ggplot(data=p12[complete.cases(p12[,3]),],…)
将仅绘制两行,其中包含
ColB
中的值。否则,保留
Var1
标签并且不显示任何数据(在我看来,尽管这条规则肯定存在例外情况)通常很重要。使用dplyr中的
filter
函数:
p12%>%filter(!is.na(ColB))%%>%ggplot(aes(x=Var1,y=ColB,fill=Var1))+…