-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata-visualization.Rmd
More file actions
185 lines (127 loc) · 4.15 KB
/
data-visualization.Rmd
File metadata and controls
185 lines (127 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
title: "Data visualization"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Data visualization}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
eval = TRUE,
echo = TRUE,
comment = "#>",
dpi = 150,
fig.align = "center",
out.width = "80%",
fig.height = 4,
fig.width = 7
)
```
The package `forcis` provides [numerous functions](https://docs.ropensci.org/forcis/reference/index.html#visualization-tools) to visualize FORCIS data. This vignette shows how to use and customize these functions.
## Setup
First, let's import the required packages.
```{r setup}
library(forcis)
library(ggplot2)
```
Before proceeding, let's download the latest version of the FORCIS database.
```{r 'download-db', eval=FALSE}
# Create a data/ folder ----
dir.create("data")
# Download latest version of the database ----
download_forcis_db(path = "data", version = NULL)
```
The vignette will use the plankton net data of the FORCIS database. Let's import the latest release of the data.
```{r 'load-data', echo=FALSE}
file_name <- system.file(
file.path("extdata", "FORCIS_net_sample.csv"),
package = "forcis"
)
net_data <- read.csv(file_name)
```
```{r 'load-data-user', eval=FALSE}
# Import net data ----
net_data <- read_plankton_nets_data(path = "data")
```
**NB:** In this vignette, we use a subset of the plankton net data, not the whole dataset.
## Spatial visualization
### Creating a world map
The function `geom_basemap()` can be used to easily add World countries, oceans and bounding box to a `ggplot2` object.
```{r 'geom-basemap'}
# World basemap ----
ggplot() +
geom_basemap()
```
These layers come from the [Natural Earth](https://www.naturalearthdata.com/) website and are defined in the [Robinson projection](https://epsg.io/54030).
### Mapping FORCIS data
The function `ggmap_data()` can be used to plot FORCIS data on a World map. Let's map the plankton nets data.
```{r 'ggmap-raw-data'}
# Map raw net data ----
ggmap_data(net_data)
```
User can customize the aesthetic of the data:
```{r 'ggmap-raw-data-2'}
# Customize map ----
ggmap_data(net_data, col = "#ff0000", fill = NA, shape = 21, size = 3)
```
This function works with the output of various functions available in the `forcis` package. For example:
```{r 'ggmap-filtered-data', echo=TRUE, eval=FALSE}
# Filter net data ----
net_data_indian <- filter_by_ocean(net_data, ocean = "Indian Ocean")
# Map filtered data ----
ggmap_data(net_data_indian)
```
Note that the `forcis` package is pipe-friendly.
```{r 'ggmap-filtered-data-pipe', eval=FALSE}
# Same as before, but w/ the pipe ----
net_data |>
filter_by_ocean(ocean = "Indian Ocean") |>
ggmap_data()
```
You can export this map with the function `ggsave()` of the package `ggplot2`.
```{r 'ggmap-save', eval=FALSE}
# Map filtered data ----
net_data_indian_map <- net_data |>
filter_by_ocean(ocean = "Indian Ocean") |>
ggmap_data() +
ggtitle("FORCIS net data - Indian Ocean")
# Save as PNG ----
ggsave(
net_data_indian_map,
filename = "net_data_indian_map.png",
width = 20,
height = 11,
units = "cm",
dpi = 300,
scale = 1.5,
bg = "white"
)
```
## Temporal visualization
### Plot data by year of sampling
The function `plot_record_by_year()` plots the number of records (y-axis) by year (x-axis).
```{r 'plot-record-by-year'}
# Plot number of records by year ----
plot_record_by_year(net_data)
```
### Plot data by month of sampling
The function `plot_record_by_month()` plots the number of records (y-axis) by month (x-axis).
```{r 'plot-record-by-month'}
# Plot number of records by month ----
plot_record_by_month(net_data)
```
### Plot data by season
The function `plot_record_by_season()` plots the number of records (y-axis) by season (x-axis).
```{r 'plot-record-by-season'}
# Plot number of records by season ----
plot_record_by_season(net_data)
```
## Vertical visualization
### Plot data by depth of sampling
The function `plot_record_by_depth()` plots the number of records (x-axis) by depth intervals (y-axis).
```{r 'plot-record-by-depth'}
# Plot number of records by depth ----
plot_record_by_depth(net_data)
```