排除图中的分类级别

Exclude categorical level in plots

我正在使用 R,并且我有这个具有一些 'NA' 值的分类变量。我的 stats_smooth 黄土曲线在这个 NA 点没有做任何事情,因此情节看起来很奇怪。

我想要一个没有值 "NA" 的图表。

我该怎么做?

当前代码:

ggplot(data=dat, aes(factor(Make_ends_meet),number_shares)) + geom_jitter(size=2.5) + geom_violin() + stat_smooth(aes(x=Make_ends_meet, y=number_shares, group=1), method="loess")# + facet_grid(. ~ category, margins=TRUE)

情节 The Loess curve goes up, until it reaches the last categorical variable which is also a number. After that, it stops. The plot continues for categorical variable "NA", which I wish to remove so that I have a plot of values 1 - 5

在绘图之前过滤掉那些 NA 值怎么样? dplyr 解决方案可能类似于:

library(dplyr)
library(ggplot2)

dat %>%
 filter(!is.na(Make_ends_meet)) %>%
 ggplot(aes(x = factor(Make_ends_meet), y = number_shares)) + 
 geom_jitter(size=2.5) + 
 geom_violin() + 
 stat_smooth(aes(x=Make_ends_meet, y=number_shares, group=1), method="loess")