Fill area between lines using ggplot in R

Hello Everone, I am trying to fill area of my line using ggplot. I am trying to use Ribbons and area plots.
I have the following code.

library(fpp2)
library(dplyr)
library(readxlsx)
library(ggplot2)

library(scales)
library(lubridate)
library(dplyr)
library(randtests)
library(tidyr)
library(timetk)     # Toolkit for working with time series in R
library(readxl)
library(Metrics)
library(devtools)

dataset <- read_xlsx("EDA.xlsx")
colnames(dataset)<- c("Date","Average","median","minimum","maximum","Percentile_5-95","Percentile_10-90","Percentile_25-75")
db <- na.omit(dataset)
db <- as.Date(db$Date,format ="%d")
View(db)
base_plot <- ggplot() + theme_classic()
plot1 <- ggplot(data=db)+
  geom_line(data= db,aes(y=db$Average,x= db$Date,color="Average"),size=1 ) + xlab("daily mean value") + ylab("Discharge [m3/sec]") +
  geom_line(data= db,aes(y=db$median,x= db$Date,color="Median"),size=1) +
  geom_line(data= db,aes(y=db$maximum*0.5,x= db$Date,color="maximum_Scale_0.5"),size=1)+
  geom_line(data= db,aes(y=db$minimum,x= db$Date,color="Minimum"),size=1)+
  geom_line(data= db,aes(y=db$`Percentile_5-95`,x= db$Date,color="`Percentile_5-95`"),size=1)+
  geom_line(data= db,aes(y=db$`Percentile_10-90`,x= db$Date,color="`Percentile_10-90`"),size=1)+
  geom_line(data= db,aes(y=db$`Percentile_25-75`,x= db$Date,color="`Percentile_25-75`"),size=1)+
  scale_color_manual(values = c(
    'Average' = 'darkblue',
    'Median' = 'red',"maximum_Scale_0.5"= "lightsalmon2","Minimum"= "brown","`Percentile_5-95`" = "mediumorchid4","`Percentile_10-90`"= "green","`Percentile_25-75`"= "steelblue")) +
  labs(color = 'Legends')

plot2 <- plot1 + scale_y_continuous(limits = c(0,10000), breaks = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000), labels = c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000))
print(plot2)
 

Kindly guide me how I can do it and where I put it

Welcome to RStudio Community.

Firstly, I'd really encourage you check out our guide for asking R-coding questions. FAQ: Tips for writing R-related questions.
It encourages to ask questions like this with a reprex. Right now, we can't replicate your code since it reviews to a file loaded from your machine. It's much preferable to set-up questions as an encapsolated reprex.

On this, your example is a little confusing. There are images with ribbons, possibly error bars. The code provided doesn't seem to refer to geom_ribben.

I'd suggest checking out the examples of geom_ribbon in the ggplot2 documentation,

For example;

huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
h <- ggplot(huron, aes(year))
# Add aesthetic mappings 
h + 
  geom_ribbon(
    aes(ymin = level - 1, ymax = level + 1), fill = "grey70") + 
  geom_line(aes(y = level))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.