0

我有大约 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

整个数据集可在以下链接中获得

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

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

我想绘制以下信息

1:- 年平均流量 在此处输入图像描述 3:- 排名平均年流量 在此处输入图像描述 3:- 流型 在此处输入图像描述

谢谢

4

1 回答 1

1

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


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 包于 2020-11-26 创建(v0.3.0)

于 2020-11-26T11:02:22.503 回答