I am trying to plot a regression line for how the wing length for a species of birds looks like over a year. I am using data from multiple years but I want to compress data from all years to only show the change of day of the year. For this I have taken the date and reformated it to only include month and day:
date <- format(BIRD$DATUM, "%b %d")
I have then attempted to define what coefficients it will use when running the plot:
coefs <- coef(lm(WING~ date, data = SISKIN))
Finally I have the code for the plot:
ggplot(BIRD, aes(date, WING, group = date)) +
geom_boxplot(fill="white", color="black", width= 0.8) +
ggtitle("BIRD DOY") +
xlab("DOY") +
ylab("Wing length (mm)") +
theme_bw() +
theme(axis.title = element_text(size = 9)) +
stat_summary(fun = mean, color="red", geom = "point") +
theme(axis.text= element_text(size= 7, angle = 0)) +
geom_abline(intercept = coefs[1], slope = coefs[2], color = "red")
Once I run this, the regression line only shows the relationship between the first and second data entry disregarding all other points. I want it to include all points.
BONUS: I also want to sequence the x-axis so that it is not so cluttered.
Dummy of data:
DATUM
1986-09-25
1987-10-03
1988-08-15
1990-09-12
WING
75
73
76
75