如何绘制每小时降雨时间序列

时间:2017-05-25 13:18:52

标签: r

我的时间序列有以下格式,我必须绘制每小时的时间序列,任何人都可以知道如何做到这一点。我不想仅绘制-9999值的实际降水值

**Precipitation                             
YY      MM  DD  HH  365         877         
YY      MM  DD  HH  5643798.4   5623228.2   4622030    4622789      4621870
YY      MM  DD  HH  4620564.8   4623768.4   5634890    5633638      5633942
YY      MM  DD  HH  991         5779        53718629    53718621    53718622**
1995    9   1   0    -9999      5.5        -9999       -9999    -9999
1995    9   1   1    -9999      5.7        -9999       -9999    -9999
1995    9   1   2     -9999     6.8        -9999       -9999    -9999
1995    9   1   3     -9999     5.6        -9999       -9999    -9999
1995    9   1   4     -9999     5.9        -9999       -9999    -9999
1995    9   1   5     -9999     5.2        -9999       -9999    -9999
1995    9   1   6      -9999      8        -9999       -9999    -9999
1995    9   1   7     -9999     4.5        -9999       -9999    -9999

1 个答案:

答案 0 :(得分:0)

使用stringrlubridatetidyverse

假设你像这样构建你的df:

> prec_df
# A tibble: 8 × 9
Year Month   Day  Hour    x0 Precipitation    x1    x2    x3
<dbl> <dbl> <dbl> <dbl> <dbl>         <dbl> <dbl> <dbl> <dbl>
1  1995     9     1     0 -9999           5.5 -9999 -9999 -9999
2  1995     9     1     1 -9999           5.7 -9999 -9999 -9999
3  1995     9     1     2 -9999           6.8 -9999 -9999 -9999
4  1995     9     1     3 -9999           5.6 -9999 -9999 -9999
5  1995     9     1     4 -9999           5.9 -9999 -9999 -9999
6  1995     9     1     5 -9999           5.2 -9999 -9999 -9999
7  1995     9     1     6 -9999           8.0 -9999 -9999 -9999
8  1995     9     1     7 -9999           4.5 -9999 -9999 -9999

您可以使用:

library(tidyverse)
library(lubridate)
library(stringr)
prec_df %>% mutate(utc = lubridate::ymd_h( str_c( Year, Month, Day, Hour, sep =":") ) ) %>% 
ggplot() + geom_line(aes(x = utc, y = Precipitation))