EDIT: I have tried what has been suggested to me but na.omit is plotting my NAs as if they are a value. I have also updated my post with some sample data, and a new ggplot script to reflect suggestions made to me.
I am trying to plot monthly data in ggplot, using geom line. However, there are months where I do not have data. For example, I have data for the months of, April, May, June, and July
, no data in August
, and then data again in September
. What I would like to do is plot months, including the months without data in order to represent time scale correctly. I have quite a few gaps where there is no data for several months (due to a shift from monthly to seasonal surveillance), but would still like all months to show general trend.
Below is some sample data (all columns are Factors), my code, and a screen grab of my output.
Sample Data
Material Month RelativeFrequency
1 Compost Apr 2017 29.2817679558011
2 Hybrid Apr 2017 37.292817679558
3 Wood Chips Apr 2017 33.4254143646409
4 Compost May 2017 28.8401253918495
5 Hybrid May 2017 34.4827586206897
6 Wood Chips May 2017 36.6771159874608
7 Compost Aug 2017 NA
8 Hybrid Aug 2017 NA
9 Wood Chips Aug 2017 NA
Script
library (ggplot2)
ggplot(data = Mound.Freq, aes(x = Month, y = RelativeFrequency, color =
Material, group =
Material))+
geom_point(data = na.omit(Mound.Freq))+
geom_line(data = na.omit(Mound.Freq))+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Thanks!