I am trying to plot several things in a chart. Points colored by ID, the regression line, a modified regression line and an area where I do not want values to fall in.
I would like to have a legend with the names of the two lines. e.g. blue=Fitted model, red=Worst case scenario and the area, red= Suspect values.
This is the code that I used to create the graph:
ggplot(data, aes(x=log_dilution, y=ct)) +
geom_point(aes(color=ID),show.legend = FALSE) +
geom_smooth(aes(linetype ='Fitted model +95%CI'), method = 'lm',show.legend = TRUE) +
geom_segment(aes(x = 0, xend = 1.7, y = model1$coefficients[1], yend
=model1$coefficients[1] + (model1$coefficients[2]+(1.96*1.030535))*1.7),
color='red', lwd=1, lty=2,show.legend = FALSE) +
theme(axis.text.x= element_text(size=14), axis.title= element_text(size=16), axis.text.y = element_text(size=14)) +
ylim(15, 40) +
annotate('rect',xmin=0, xmax=1.7, ymin=35, ymax=40, alpha=0.2, fill="red") +
scale_size_manual( values = c(1.5, 1.5), labels = c("Fitted model +95%CI", "Worst case")) +
guides(color=FALSE)+ylab("Ct")+theme(legend.position = "bottom")
and this is the result so far.
Can anybody give me some directions on how I can plot a legend for the lines and the area (i am not interested in plotting the points)?