Adding 2 time specific ablines to a plot (ggplot 2)

Hi,

I am basically a beginner with R so apologies if this is overly simple!
I would like to use ggplot to create my graphs but cannot work out how to add ablines which are specific to certain sections of the year.

I can complete the plot using the base R plots (see below) but cannot work out how to do it with ggplot!
Here is the base R plot and the code used:
#Eristalis tenax
plot(syrphidae[syrphidae$Species=="Eristalis tenax",]$Date, syrphidae[syrphidae$Species=="Eristalis tenax",]$latitude, xlab="Date", ylab="Latitude", main = "Eristalis tenax")
spring1<-lm(latitude~Date, data=subset(syrphidae[syrphidae$Species=="Eristalis tenax",], Date<=181))
abline(spring1, col="green")
autumn1<-lm(latitude~Date, data=subset(syrphidae[syrphidae$Species=="Eristalis tenax",], Date>=212))
abline(autumn1, col="orange")

This is my current code for my ggplot2 attempt:
ggplot(eristalis, aes(x=Date, y=latitude)) +
geom_point() +
xlab("Date") +
ylab("Latitude") +
ggtitle("Eristalis tenax")

This gives me the scatter plot but without the lines of course.

Any help would be greatly appreciated, I'm much better at going out and finding the animals than I am at analysing their stats!

Cheers,

Will

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.