I am a total beginner using R for a university project
I need to create a line plot using two datasets, and have two lines from each data set.
right now i have two plots, for which i do not know how to add a legend, and i do not know how to use na.rm to ignore missing data points. eventually i will need to combine these two plots into one if possible
here is my current code.
file = "AA1 Log.R"
library(ggplot2)
require(ggplot2)
CA=(NTN_ca45_a_s_mgl)
PA=(NTN_pa29_a_s_mgl)
###scatter plot of SO4 and NO3 over time for PA###
ggplot(data= PA, aes(x=yr)) +
geom_line(aes(y = SO4), color = "red") +
geom_line(aes(y = NO3), color = "blue") +
labs(y='Compound concentration',x='Year') +
theme_classic() +
ggtitle("Concentration of SO4 and NO3 over time in Pennsylvania")
###scatter plot of SO4 and NO3 over time for CA###
ggplot(data= CA, aes(x=yr), color= y)+
geom_point(aes(y = SO4), color = "orange") +
geom_path(aes(y = SO4), color = "orange") +
geom_point(aes(y = NO3), color = "green") +
geom_path(aes(y = NO3), color = "green") +
labs(y='Compound concentration',x='Year',
title = "Concentration of SO4 and NO3 over time in California", ) +
theme_classic() +
Just to expand @M_AcostaCH 's point, we need a reproducible example (reprex)
aAd sample data. A handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with.