I would like to have different types of loess lines for the two months in the attached data set. The graph produced by the ggplot script given below is nearly exactly what I want, but the same type of line (I set it to 2, a dash) is used for both August and November.
How can the type of loess line (solid vs. dash, for example) be made to depend on a factor, in this case Month?
data<- read.csv("testdata.csv", header=T)
df <- data.frame (Year=factor(data$Year), Month=factor(data$Month),
Salinity=data$Salinity, Chl=data$Chl)
library(ggplot2)
ggplot(df, aes (x=Salinity, y=Chl, group=Month, fill=Month))+
geom_point(size = 1, aes(fill = NULL)) +
geom_point(size = 1, aes(alpha = Month)) +
scale_shape_manual(values = c(21, 22, 23)) +
scale_color_manual(values = c("black", "black")) +
scale_fill_manual(values = c("black", "white")) +
scale_alpha_manual(values = c(1, 0))+
geom_point(aes(shape=Year))+
stat_smooth (method="loess", se=F, color="black",linetype=2, show_guide=F)+
xlab("Salinity") +
ylab( expression(paste("Chlorophyll a (", mu,"g ", L^{-1},")")))+
scale_y_continuous (limits=c(0, 25))+
coord_fixed(ratio=1)+
guides(alpha = guide_legend(override.aes = list(shape = 21, fill = c("black", NA), alpha =c(1,1))))+
theme_classic(base_size = 14, base_family = "")