[R] Adding non-data line to legend ggplot2 Maximum Contaminant Level
kydaviddoyle at gmail.com
Tue Sep 26 21:51:32 CEST 2017
I have a plot showing chloride concentrations for various point over time.
I also have a dotted line that show the Secondary Maximum Contaminant Level
(my screening limit) on the graphs at 250 mg/L. But I can not figure out
how to include the dotted line / Secondary Maximum Contaminant Level in
the legend. Any thoughts? My code is as following and is linked to my
data on the net.
Thank you in advance
#Loads the ggplot2 package.
##This loads your data from your worksheet
#Sets which are detections and nondetects
MyData$Detections <- ifelse(MyData$D_Chloride ==1, "Detected", "NonDetect")
#does the plot
p <- ggplot(data = MyData, aes(x=Year, y=Chloride , col=Detections)) +
#sets the detect vs. non-detect colors
#sets the y scale and log base 10
#location of the legend
#sets the line color, type and size
geom_line(colour="black", linetype="dotted", size=0.5) +
## does the graph using the Location IDs as the different Locations.
p + facet_grid(Location ~ .)
[[alternative HTML version deleted]]
More information about the R-help