I'm making some forecasts with the prophet package
library("tidyverse")
library("lubridate")
library("prophet")
ds <- dmy_hms("01.01.2016 0:00:00", "01.02.2016 0:00:00", "01.03.2016 0:00:00", "01.04.2016 0:00:00", "01.05.2016 0:00:00", "01.06.2016 0:00:00",
"01.07.2016 0:00:00", "01.08.2016 0:00:00", "01.09.2016 0:00:00", "01.10.2016 0:00:00", "01.11.2016 0:00:00", "01.12.2016 0:00:00",
"01.01.2017 0:00:00", "01.02.2017 0:00:00", "01.03.2017 0:00:00", "01.04.2017 0:00:00", "01.05.2017 0:00:00", "01.06.2017 0:00:00",
"01.07.2017 0:00:00", "01.08.2017 0:00:00", "01.09.2017 0:00:00", "01.10.2017 0:00:00", "01.11.2017 0:00:00", "01.12.2017 0:00:00",
"01.01.2018 0:00:00", "01.02.2018 0:00:00", "01.03.2018 0:00:00", "01.04.2018 0:00:00", "01.05.2018 0:00:00", "01.06.2018 0:00:00")
y <- c(899, 1178, 1586, 1717, 1166, 2113, 4136, 3096, 3379, 3229, 1814, 3207, 1173, 1036, 1361, 1179,1267, 2292, 3527, 3049, 3050, 3580, 2129, 2650, 1370, 1169, 1280, 1889, 1245, 2199)
y1 <- c(868, 882, 2274, 3390, 4781, 2803, 5545, 7226, 1526, 1748, 578, 1316, 833, 1199, 2447, 2465, 3601, 3165, 5828, 4590, 2692, 1549, 825, 1013, 1135, 962, 2057, 3437, 4689,3966)
df1 <- data.frame(ds, y, group = "group1" )
df2 <- data.frame(ds, y = y1, group = "group2" )
df <- bind_rows(df1, df2)
df_nested <- df %>% nest( - group) %>%
mutate(m = map(data, prophet, yearly.seasonality = TRUE)) %>%
mutate(future = map(m, make_future_dataframe, period = 7, freq = 'month')) %>%
mutate(forcast = map2(m, future, predict))
after this, I'd like to make graphs for every forecast I've got, so I apply map2
from purrr
package:
map2(df_nested$m, df_nested$forcast, plot, ylab = df_nested$group)
So I get for the first plot group 1 forecast plot
and for the second plot I've still the name "group1"
How can I make the names of my plots to be the names of the groups?