I'm trying to plot a v. simple boxplot in ggplot2. I have species richness vs. landuse class. However, I have 2 NA's in my data. For some strange reason, they're being plotted, even when they're being understood as NA's by R. Any suggestion to remove them?
The code I'm using is:
ggplot(data, aes(x=luse, y=rich))+
geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot", position = "dodge", outlier.colour = "red", outlier.shape = 16, outlier.size = 2, notch = F, notchwidth = 0.5)+
scale_x_discrete("luse", drop=T)+
geom_smooth(method="loess",aes(group=1))
However, the graph includes 2 NA's for luse. Unfortunately I cannot post images, but imagine that a NA bar is being added to my graph.
ggplot(na.omit(data), aes(x=luse, y=rich)) + ...
– Designerna.omit(data)
will remove observations with missings on any variable. This can have unintended consequences for your graphs and/or analysis. One could usedata=na.omit(data[,c("var1","var2",...)])
, where var1, var2, ... are the variables you require for your graph. – Goshorn