Fitting trend-line on multiple plots using ggplot2

I can't work with your exact same code since you haven't provided a proper REPRoducible EXample (reprex) illustrating your issue, but I have made this example with the file link you have shared.

library(tidyverse)
library(lubridate)

url <- "https://drive.google.com/u/0/uc?id=16k1cMMr1dthJOsppazVZ3cUCa1rRGF9m&export=download"
nf <- read.csv(url)

nf %>%
    mutate_at(vars(starts_with("date")), as.Date) %>%
    select(date_mpi, mpi_tas, hadgem_tas, gfdl_tas) %>% 
    gather(group, temperature, -date_mpi) %>%
    ggplot(aes(x = date_mpi, y = temperature, colour = group)) +
    geom_line() +
    geom_smooth(method = "lm", se=FALSE) +
    labs(title = "Annual temperature trends",
         x = "Near-future projection",
         y = "Temperature [°C]") + 
    scale_y_continuous(limits = c(24,31)) +
    scale_color_discrete(labels = c("mpi_tas"='WRF-MPI-ESM MR',
                                    "hadgem_tas"='WRF-HadGEM2-ES',
                                    "gfdl_tas" ='WRF-GFDL-ESM2M')) +
    theme(legend.position = c(.1,.85))
#> `geom_smooth()` using formula 'y ~ x'

1 Like