You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/getCRUCLdata.Rmd
+14-16Lines changed: 14 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "getCRUCLdata"
3
3
author: "Adam H. Sparks"
4
-
date: "2024-12-15"
4
+
date: "2024-12-16"
5
5
output:
6
6
rmarkdown::html_vignette:
7
7
toc: true
@@ -12,6 +12,7 @@ vignette: >
12
12
%\VignetteDepends{terra}
13
13
%\VignetteDepends{ggplot2}
14
14
%\VignetteDepends{viridis}
15
+
%\VignetteDepends{data.table}
15
16
---
16
17
17
18
@@ -64,7 +65,7 @@ The arguments for selecting the climatology elements for importing are:
64
65
-**dsn***For `create_CRU_stack()`* and *`create_CRU_df()`* only.
65
66
Local file path where CRU CL v. 2.0 .dat.gz files are located.
66
67
67
-
### Creating tidy data frames for use in R
68
+
### Creating data frames for use in R
68
69
69
70
The `get_CRU_df()` function automates the download process and creates data frames of the climatology elements.
70
71
@@ -114,7 +115,7 @@ CRU_data
114
115
#> 6795150: -35.80
115
116
```
116
117
117
-
Perhaps you only need one or two elements, it is easy to create a tidy data frame of mean temperature only.
118
+
Perhaps you only need one or two elements, it is easy to create a data frame of mean temperature only.
118
119
119
120
120
121
```r
@@ -136,7 +137,7 @@ t
136
137
#> 6795144: 83.583 -36.750 dec -33.3
137
138
```
138
139
139
-
#### Plotting data from the tidy dataframe
140
+
#### Plotting data from the data frame
140
141
141
142
Now that we have the data, we can plot it easily using _ggplot2_ and the _viridis_ package for the colour scale.
142
143
@@ -154,8 +155,8 @@ ggplot(data = t, aes(x = lon, y = lat, fill = tmp)) +
154
155
```
155
156
156
157
<divclass="figure"style="text-align: center">
157
-
<imgsrc="plot_t-1.png"alt="plot of chunk plot_t" />
158
-
<pclass="caption">plot of chunk plot_t</p>
158
+
<imgsrc="plot_t-1.png"alt="Maps of global temperatures from CRU CL v. 2.0 climatology covering the Earth's surface from ymin = -60, ymax = 85, xmin = -180, xmax = 180 degrees from 1960 to 1991." />
159
+
<pclass="caption">Maps of global temperatures from CRU CL v. 2.0 climatology covering the Earth's surface from ymin = -60, ymax = 85, xmin = -180, xmax = 180 degrees from 1960 to 1991.</p>
159
160
</div>
160
161
161
162
We can also generate a violin plot of the same data to visualise how the temperatures change throughout the year.
<imgsrc="violin_plot-1.png"alt="plot of chunk violin_plot" />
174
-
<pclass="caption">plot of chunk violin_plot</p>
174
+
<imgsrc="violin_plot-1.png"alt="Monthly values of global temperatures from CRU CL v. 2.0 climatology covering the Earth's surface from ymin = -60, ymax = 85, xmin = -180, xmax = 180 degrees from 1960 to 1991." />
175
+
<pclass="caption">Monthly values of global temperatures from CRU CL v. 2.0 climatology covering the Earth's surface from ymin = -60, ymax = 85, xmin = -180, xmax = 180 degrees from 1960 to 1991.</p>
175
176
</div>
176
177
177
-
#### Saving the tidy `data.frame` as a CSV (comma separated values file) locally
178
+
#### Saving the `data.frame` as a CSV (comma separated values file) locally
178
179
179
-
Save the resulting tidy `data.frame` to local disk as a comma separated (CSV)
180
+
Save the resulting `data.frame` to local disk as a comma separated (CSV)
180
181
file to local disk, using _data.table_'s `fwrite()`.
181
182
182
183
183
184
```r
185
+
library(data.table)
184
186
fwrite(x=t, file="~/CRU_tmp.csv")
185
187
```
186
188
187
189
### Creating terra raster stacks for use in R and saving for use in another GIS
188
190
189
191
For working with spatial data, _getCRUCLdata_ provides a function that create lists of _terra_ stacks of the data.
190
192
191
-
The `get_CRU_stack()` functions provide similar functionality to `get_CRU_df()`, but rather than returning a tidy data frame, it returns a list of `terra::rast()` objects for use in an R session.
193
+
The `get_CRU_stack()` functions provide similar functionality to `get_CRU_df()`, but rather than returning a data frame, it returns a list of `terra::rast()` objects for use in an R session.
192
194
193
195
The `get_CRU_stack()` function automates the download process and creates a `terra::rast()` object of the CRU CL v. 2.0 climatology elements.
194
196
Illustrated here is creating a `terra::rast()` of all CRU CL v. 2.0 climatology elements available.
Perhaps you only need one or two elements, it is easy to create a tidy data frame of mean temperature only.
98
+
Perhaps you only need one or two elements, it is easy to create a data frame of mean temperature only.
98
99
99
100
```{r get_t_only, eval=TRUE}
100
101
t <- get_CRU_df(tmp = TRUE)
101
102
102
103
t
103
104
```
104
105
105
-
#### Plotting data from the tidy dataframe
106
+
#### Plotting data from the data frame
106
107
107
108
Now that we have the data, we can plot it easily using _ggplot2_ and the _viridis_ package for the colour scale.
108
109
109
-
```{r plot_t, eval=TRUE, message=FALSE}
110
+
```{r plot_t, eval=TRUE, message=FALSE, fig.cap="Maps of global temperatures from CRU CL v. 2.0 climatology covering the Earth's surface from ymin = -60, ymax = 85, xmin = -180, xmax = 180 degrees from 1960 to 1991."}
110
111
library(ggplot2)
111
112
library(viridis)
112
113
@@ -120,28 +121,29 @@ ggplot(data = t, aes(x = lon, y = lat, fill = tmp)) +
120
121
121
122
We can also generate a violin plot of the same data to visualise how the temperatures change throughout the year.
122
123
123
-
```{r violin_plot, eval=TRUE}
124
+
```{r violin_plot, eval=TRUE, fig.cap = "Monthly values of global temperatures from CRU CL v. 2.0 climatology covering the Earth's surface from ymin = -60, ymax = 85, xmin = -180, xmax = 180 degrees from 1960 to 1991."}
124
125
ggplot(data = t, aes(x = month, y = tmp)) +
125
126
geom_violin() +
126
127
ylab("Temperature (˚C)") +
127
128
labs(title = "Global Monthly Mean Land Surface Temperatures From 1960-1991",
128
129
subtitle = "Excludes Antarctica")
129
130
```
130
131
131
-
#### Saving the tidy `data.frame` as a CSV (comma separated values file) locally
132
+
#### Saving the `data.frame` as a CSV (comma separated values file) locally
132
133
133
-
Save the resulting tidy `data.frame` to local disk as a comma separated (CSV)
134
+
Save the resulting `data.frame` to local disk as a comma separated (CSV)
134
135
file to local disk, using _data.table_'s `fwrite()`.
135
136
136
137
```{r save_t, eval=FALSE}
138
+
library(data.table)
137
139
fwrite(x = t, file = "~/CRU_tmp.csv")
138
140
```
139
141
140
142
### Creating terra raster stacks for use in R and saving for use in another GIS
141
143
142
144
For working with spatial data, _getCRUCLdata_ provides a function that create lists of _terra_ stacks of the data.
143
145
144
-
The `get_CRU_stack()` functions provide similar functionality to `get_CRU_df()`, but rather than returning a tidy data frame, it returns a list of `terra::rast()` objects for use in an R session.
146
+
The `get_CRU_stack()` functions provide similar functionality to `get_CRU_df()`, but rather than returning a data frame, it returns a list of `terra::rast()` objects for use in an R session.
145
147
146
148
The `get_CRU_stack()` function automates the download process and creates a `terra::rast()` object of the CRU CL v. 2.0 climatology elements.
147
149
Illustrated here is creating a `terra::rast()` of all CRU CL v. 2.0 climatology elements available.
0 commit comments