I am currently trying to shade the region between two geom_line
s in a ggplot of time-series data in R. I am trying to do this based on which line has the highest value at a given time (i.e if the blue line has the highest value shade the region between the two lines blue and vice versa). I have tried an approach taking the difference between my two variables and using zero as a reference point while using geom_ribbon
but to no avail. This is the code I am currently using for my plot:
plot_against_xG = data_select %>%
ggplot(aes(x = Date, GF = GF_rolling_5_game_avg, xG = xG_rolling_5_game_avg)) +
geom_line(aes(y = GF_rolling_5_game_avg, colour="GF")) +
geom_line(aes(y = xG_rolling_5_game_avg, colour="xG")) +
ggtitle("Season 1") +
ylab("Points") +
scale_color_manual(values = c(GF = "blue", xG = "red"),
labels = c(GF = "GF", xG = "xG"))
plt11 <- ggplotly(plot_against_xG, tooltip = c("x", "GF", "xG"))
The resultant plot is: