我之前发表过一篇关于试图获得类似这样的图表的帖子:http: //i.imgur.com/HVuxOKy.png
到目前为止,我的图表如下所示:http: //imgur.com/Tw7SNWC
到目前为止,这是我的代码,我非常感谢任何反馈或改进它的方法,因为我对 R 比较陌生。我遇到的主要问题之一是将所有数据(1953-2013)绘制到一个水上年(10 月至 9 月)。我创建了一个解决方案,但我确定它并不理想。
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"))
正如你所看到的,我非常接近我想要的,但是我有一段时间让丝带(多边形?)工作,因为我不知道如何使“ymin”和“ymax”变量基于在我的数据上。
任何意见或想法将不胜感激!!!
谢谢!