I made a previous post about trying to get a graph similar to this: https://i.stack.imgur.com/neIEz.png
So far my graph looks like this: https://i.stack.imgur.com/aXKVD.jpg
Here is my code so far, I would really appreciate any feedback or ways to improve it since I am relatively new to R. One of the main problems I ran into getting all of the data (1953-2013) to be graphed onto one water year (Oct-Sept). I created a solution, though I'm certain it's not ideal.
library(ggplot2)
library(plyr)
library(reshape2)
library(scales)
## Read Data
df <- read.csv("Salt River Flow.csv")
## Convert Date column to R-recognized dates
df$Date <- as.Date(df$Date, "%m/%d/%Y")
## Finds Water Years (Oct - Sept)
df$WY <- as.POSIXlt(as.POSIXlt(df$Date)+7948800)$year+1900
## Normalizes Water Years so stats can be applied to just months and days
df$w <- ifelse(month(df$Date) %in% c(10,11,12), 1900, 1901)
## Creates New Date (dat) Column
df$dat <- as.Date(paste(df$w,month(df$Date),day(df$Date), sep = "-"))
## Creates new data frame with summarised data by MonthDay
PlotData <- ddply(df, .(dat), summarise,
Min = min(Flow), "10%" = quantile(Flow, p = 0.05), "25%" = quantile(Flow, p = 0.25),
Median = quantile(Flow, p = 0.50), Mean = mean(Flow), "75%" = quantile(Flow, p = 0.75),
"90%" = quantile(Flow, p = 0.90), Max = max(Flow))
## Melts data so it can be plotted with ggplot
m <- melt(PlotData, id="dat")
## Plots
p <- ggplot(m, aes(dat, value, group = variable, colour = variable))
+ geom_line() + labs(x = "Month",y = "Flow") +
scale_x_date(labels=date_format("%b"))
As you can see, I am pretty close to what I want, but am having a heck of a time getting the ribbons (polygons?) to work because I don't know how to make the "ymin" and "ymax" variable based on my data.
Any comments or thoughts would be greatly appreciated!!!
Thank you!