Since the OP did not provide a MRE (see here for how to make one in R), I'm using the flights
dataset from the nycflights13
package.
library(ggplot2)
library(dplyr)
library(lubridate)
library(nycflights13) # https://github.com/hadley/nycflights13
dataset <-
flights %>%
# create departure date
mutate(departure = make_date(year, month, day)) %>%
# calculate average departure delay
group_by(departure) %>%
summarize(dep_delay_mean = mean(dep_delay, na.rm = TRUE)) %>%
# remove outlier
filter(dep_delay_mean < 60)
head(dataset)
# A tibble: 6 x 2
departure dep_delay_mean
<date> <dbl>
1 2013-01-01 11.5
2 2013-01-02 13.9
3 2013-01-03 11.0
4 2013-01-04 8.95
5 2013-01-05 5.73
6 2013-01-06 7.15
ggplot(data = dataset, aes(x = departure, y = dep_delay_mean)) +
geom_point(colour = "red") +
geom_line(colour = "blue") +
geom_smooth(method = "lm", colour = "orange", se = FALSE) +
theme_minimal()
