年度时间序列数据绘图

Annual Time Series Data Plotting

我有大约 60 个具有以下时间序列格式的流量测量站,

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

整个数据集可在以下位置获得link

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

水年从十月开始到九月结束(比如说10/01/1939到09/30/1940,这定义为1940水年)

我要绘制以下信息

1:-平均年流量 3:- 排名平均年流量 3:- 流动模式

谢谢

在询问 SO 之前,您真的应该努力尝试自己解决这个问题。 google 搜索即可找到许多很棒的指南。然而,这件事并不容易,我想在你的路上帮助你。


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')

reprex package (v0.3.0)

于 2020-11-26 创建