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 月に始まります (たとえば、1939 年 10 月 1 日から 1940 年 9 月 30 日まで、これは 1940 年と定義されます)。

次の情報をプロットしたい

1: -平均年間流量 3 ここに画像の説明を入力 :-ランク付けされた平均年間流量 ここに画像の説明を入力 3:-流量パターン ここに画像の説明を入力

ありがとう

4

1 に答える 1

1

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 パッケージ(v0.3.0)により 2020-11-26 に作成

于 2020-11-26T11:02:22.503 に答える