basicr_on_data.luftkval.oslo10.Rmd 3.22 KB
Newer Older
jml's avatar
jml committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
---
title: "basicr on data.luftkval.oslo10"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{luft}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
library(basicr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```

## Basic analysis on 'data.luftkval.oslo10' df.

### install
```R
library("devtools")
20

jml's avatar
jml committed
21
22
23
devtools::install_git("https://git.nilu.no/rfriendlyr/friendlyr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/d.luft.oslyr.git")

24
25
26
27
28
29
30
devtools::install_git("https://git.nilu.no/rdiagnosis/basicr.git")

# remarks
# basicr requires ggplot2 version 3.1.1
remove.packages("ggplot2")
install.packages("https://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_3.1.1.tar.gz", repo=NULL, type="source")

jml's avatar
jml committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
```

### Get the 'data.luftkval.oslo10' dataset with friendlyr.

The dataset represents real observations, meaning that it contains errors.
It is possible to know the quality of the value by requesting the qa flags with 'friendlyr::qa()', cf this [vignette](https://git.nilu.no/rfriendlyr/friendlyr/blob/master/vignettes/data.luftkval.oslo10.Rmd)

```R

fromDate <- "2004/01/01 00:00:00"
toDate <- "2018/12/31 23:00:00"
timeResolution <- "hourly"
precision <- "hourly"

element_id <- c("NO2")

# station ids
station_id <- c("7","848","464","827","665","9","11","163","504","809")


# luft
luft <- friendlyr::ts(service="d.luft.oslyr",
                 fromDate=fromDate,toDate=toDate,precision=timeResolution,timeResolution=timeResolution,
                 element_id=element_id,station_id=station_id)

56
# filter values equal to -9900 used as NA
jml's avatar
jml committed
57
58
varnames <- setdiff(names(luft), friendlyts::get_name_date_col(precision))

59
60
library(dplyr)
library(tidyr)
jml's avatar
jml committed
61
tmp <- luft %>% select(names(luft)) %>%
62
                gather(variable, value, -c(friendlyts::get_name_date_col(precision))) %>%
63
                mutate(value = replace(value, value == -9900, NA)) %>%
64
                spread(variable, value) %>% friendlyts::as_tbl_friendlyts(precision=precision,date_type="friendlyts")
jml's avatar
jml committed
65
66
67

```

68
69
70
71
### Missing values

```R

72
basicr::plot_notna_ts(x=tmp,timeResolution=timeResolution,DESKTOP=TRUE)
73
74
75

```

76
### basics characteristics
jml's avatar
jml committed
77
78
79

```R

80
81
82
83
84
85
86
basicr::basic_info(df=tmp,target="NO2_7",group="none")
basicr::basic_info(df=tmp,target="NO2_7",group="YEAR")
basicr::basic_info(df=tmp,target="NO2_7",group="MONTH")
basicr::basic_info(df=tmp,target="NO2_7",group="WDAY")
basicr::basic_info(df=tmp,target="NO2_7",group="HOUR")
basicr::basic_info(df=tmp,target="NO2_7",group=c("YEAR","MONTH"))
res <- basicr::basic_info(df=tmp,target="NO2_7",group=c("MONTH","WDAY","HOUR"))
jml's avatar
jml committed
87

88
89
90
basicr::plot_tbl_basic(tmp,target="NO2_7",group="HOUR",y_name="[ug/m3]")
basicr::plot_tbl_basic(tmp,target="NO2_7",group="WDAY",y_name="[ug/m3]")
basicr::plot_tbl_basic(tmp,target="NO2_7",group="MONTH",y_name="[ug/m3]")
jml's avatar
jml committed
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
```

### Timeseries of basic characteristics and box-whisker timeseries plot with observation timeseries

```R

res <- basicr::basic_ts(df=tmp,target="NO2_7",group=c("WDAY","HOUR"),precision="hourly")
basicr::plot_boxwhisk_ts(x=res,fromDate="2004/01/05 00:00:00",toDate="2004/01/06 00:00:00",timeResolution="hourly",DESKTOP=TRUE)

```

### L-moment

```R
jml's avatar
jml committed
106

107
lmom_ <- basicr::samlmu2(df=tmp,target=varnames)
jml's avatar
jml committed
108

109
basicr::plot_lmrd(x=lmom_,DESKTOP=TRUE)
jml's avatar
jml committed
110
111
112


```