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
@@ -53,11 +52,10 @@ data values as stored in a raster and how R handles these elements.
53
52
54
53
We will continue to work with the `dplyr` and `ggplot2` packages that were introduced
55
54
in the [Introduction to R for Geospatial Data](https://datacarpentry.org/r-intro-geospatial/) lesson. We will use two additional packages in this episode to work with raster data - the
56
-
`raster` and `rgdal` packages. Make sure that you have these packages loaded.
55
+
`raster` and `sf` packages. Make sure that you have these packages loaded.
57
56
58
57
```{r load-libraries-2, eval=FALSE}
59
-
library(raster)
60
-
library(rgdal)
58
+
library(terra)
61
59
library(ggplot2)
62
60
library(dplyr)
63
61
```
@@ -86,14 +84,14 @@ data before we read that data into R. It is ideal to do this before importing
We can use `ggplot()` to plot this data. We will set the color scale to `scale_fill_viridis_c`
168
-
which is a color-blindness friendly color scale. We will also use the `coord_quickmap()` function to use an approximate Mercator projection for our plots. This approximation is suitable for small areas that are not too close to the poles. Other coordinate systems are available in ggplot2 if needed, you can learn about them at their help page `?coord_map`.
162
+
We can use `ggplot()` to plot this data. We will set the color scale to
163
+
`scale_fill_viridis_c` which is a color-blindness friendly color scale. We will
164
+
also use the `coord_quickmap()` function to use an approximate Mercator
165
+
projection for our plots. This approximation is suitable for small areas that
166
+
are not too close to the poles. Other coordinate systems are available in
167
+
ggplot2 if needed, you can learn about them at their help page `?coord_map`.
169
168
170
169
```{r ggplot-raster, fig.cap="Raster plot with ggplot2 using the viridis color scale"}
171
170
@@ -189,7 +188,7 @@ More information about the Viridis palette used above at
189
188
190
189
## Plotting Tip
191
190
192
-
For faster, simpler plots, you can use the `plot` function from the `raster` package.
191
+
For faster, simpler plots, you can use the `plot` function from the `terra` package.
193
192
194
193
::::::::::::::: solution
195
194
@@ -222,7 +221,7 @@ We can view the CRS string associated with our R object using the`crs()`
222
221
function.
223
222
224
223
```{r view-resolution-units}
225
-
crs(DSM_HARV)
224
+
crs(DSM_HARV, proj = TRUE)
226
225
```
227
226
228
227
::::::::::::::::::::::::::::::::::::::: challenge
@@ -254,7 +253,8 @@ and datum (`datum=`).
254
253
255
254
### UTM Proj4 String
256
255
257
-
Our projection string for `DSM_HARV` specifies the UTM projection as follows:
256
+
A projection string (like the one of `DSM_HARV`) specifies the UTM projection
# aggregate cells from 0.25m to 2m for plotting to speed up the lesson and
349
351
# save memory
@@ -389,19 +391,25 @@ ggplot() +
389
391
390
392
```
391
393
392
-
If your raster already has `NA` values set correctly but you aren't sure where they are, you can deliberately plot them in a particular colour. This can be useful when checking a dataset's coverage. For instance, sometimes data can be missing where a sensor could not 'see' its target data, and you may wish to locate that missing data and fill it in.
394
+
If your raster already has `NA` values set correctly but you aren't sure where
395
+
they are, you can deliberately plot them in a particular colour. This can be
396
+
useful when checking a dataset's coverage. For instance, sometimes data can be
397
+
missing where a sensor could not 'see' its target data, and you may wish to
398
+
locate that missing data and fill it in.
393
399
394
-
To highlight `NA` values in ggplot, alter the `scale_fill_*()` layer to contain a colour instruction for `NA` values, like `scale_fill_viridis_c(na.value = 'deeppink')`
400
+
To highlight `NA` values in ggplot, alter the `scale_fill_*()` layer to contain
401
+
a colour instruction for `NA` values, like `scale_fill_viridis_c(na.value = 'deeppink')`
395
402
396
403
```{r, echo=FALSE}
397
404
# demonstration code
398
405
# function to replace 0 with NA where all three values are 0 only
0 commit comments