从geom-bar移除NA

时间:2018-12-03 12:10:25

标签: r ggplot2

如何使用以下代码删除NA响应?

bar <- ggplot(newdata)
bar + stat_summary(
  aes(x = preferred.actual.factor, y = lifesatisfaction, fill = gender),
  fun.y = mean,
  geom = "bar",
  position = "dodge"
) + stat_summary(
  aes(x = preferred.actual.factor, y = lifesatisfaction, fill = gender),
  fun.data = mean_cl_normal,
  geom = "errorbar",
  position = position_dodge(width = 0.90),
  width = 0.2
) + labs(x = "Time Mismatch", y = "Life Satsifaction")

1 个答案:

答案 0 :(得分:0)

如果要从数据框中删除它,则可以在绘制之前尝试这些选项。

要删除任何列中均不包含NA的案例,

newdata <- na.omit(newdata)

要删除特定列中不适用的案件:

newdata <- newdata[!is.na(newdata$your_column_name),]