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