简体   繁体   中英

Annual Time Series Data Plotting

I have about 60 flow gauging stations with the following time series format,

date,flow
10/1/1939,64
10/2/1939,66
10/3/1939,68
10/4/1939,200
10/5/1939,280
10/6/1939,200
10/7/1939,150
10/8/1939,120
10/9/1939,100
10/10/1939,90
10/11/1939,85
10/12/1939,81
10/13/1939,78
10/14/1939,75
10/15/1939,72
10/16/1939,70
10/17/1939,100

The entire dataset is available at the following link

https://drive.google.com/file/d/1PsU5ZaOcyWMxzl7NVdeMPbP2UxLBO2Bn/view?usp=sharing

The water year starts at October end at September (say 10/01/1939 to 09/30/1940, this is defined as 1940 water year)

I want to plot the following information

1:-Mean Annual Flow 在此处输入图像描述 3:- Ranked Mean Annual Flow 在此处输入图像描述 3:- Flow Pattern 在此处输入图像描述

Thanks

You really should make an effort and try to solve this yourself before asking SO. There are many great guides just a google search away. However, this stuff isn't easy and I would like to help you on your way.


library(tidyverse)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

setwd("/Users/magnusnordmo/Desktop/Magnus/R Wizard")

df <- read_csv('flowdata.csv')
#> Parsed with column specification:
#> cols(
#>   date = col_character(),
#>   flow = col_double()
#> )

df <- df %>% 
  mutate(date = mdy(df$date))

dfyear <- df %>%
  mutate(year = floor_date(date, "year")) %>%
  group_by(year) %>%
  summarize(avg = mean(flow)) 
#> `summarise()` ungrouping output (override with `.groups` argument)

dfyear$year <- ymd(dfyear$year)

ggplot(dfyear,aes(year,avg,fill = 'streamflow')) + 
  geom_col() + 
  labs(fill = '') +
  theme(legend.position = 'bottom')




ggplot(dfyear,aes(reorder(year,-avg),avg,fill = 'streamflow')) + 
  geom_col() + 
  labs(fill = '',x = 'year') +
  scale_x_discrete(breaks = c('1953-01-01','1947-01-01','1944-01-01'),
                   labels = c('1953','1947','1944')) + 
  theme(legend.position = 'bottom')

# This plot doesnt really work in this context. Consider flipping the axis 

dfyear <- dfyear %>% 
  mutate(gmean = mean(avg)) %>% 
  mutate(diff = avg-gmean)


ggplot(dfyear,aes(year,diff,fill = 'streamflow')) + 
  geom_col() + 
  labs(fill = '') +
  theme(legend.position = 'bottom')

Created on 2020-11-26 by the reprex package (v0.3.0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM