I'm using R and I have this categorical variable that has some 'NA' values. My stats_smooth loess curve doesn't do anything at this NA point, and therefore the plot looks weird.
I'd like to have a graph without the value "NA".
How do I do this?
Current code:
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)
What about just filtering out those NA
values before the plot? A dplyr solution could look something like:
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")