Skip to content

Commit d0e02f2

Browse files
committed
updated
1 parent 018087c commit d0e02f2

11 files changed

Lines changed: 77 additions & 168 deletions

00_Admin/bibliography.bib

Lines changed: 0 additions & 85 deletions
This file was deleted.

02_Images/zhaw_lsfm_iunr_weiss.png

-33.8 KB
Binary file not shown.

02_Images/zhaw_sw_pos.png

58.2 KB
Loading

Intro/1_preparations_course.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ Now we will set some RStudio Global options. Go to *Tools → Global options*.
9191

9292
Click on "Ok" to apply the change and close the options menu.
9393

94-
[^restore]: We recommend that you start each RStudio session with a blank slate, as recommended by @wickham2017 see [here](https://r4ds.had.co.nz/workflow-projects.html)
94+
[^restore]: We recommend that you start each RStudio session with a blank slate, as recommended by @wickham2023 see [here](https://r4ds.hadley.nz/workflow-scripts#projects)
9595
[^saveworkspace]: If we don't restore the workspace at startup, there is no need to save it on exit.
9696
[^pipe]: Our group has adapted the native pipe operator `|>` to reduce package dependencies. If you use the `magrittr` pipe `%>%` and would like to stick to it, feel free.

Intro/2_preparations_project.qmd

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ As your course assignment (Leistungsnachweis) you will develop a semester projec
44

55
In fact, we give you the opportunity to track your own movement behavior, generating trajectory data you will subsequently analyze yourself. There are two ways for you to generate your own trajectory data.
66

7-
<!-- During the course, we will give you the opportunity to share your data with the other students in the course, so that the shared data pool for all can grow. -->
8-
9-
Please let us know which option you choose by filling out the following [survey](https://moodle.zhaw.ch/mod/choice/view.php?id=1192128) on Moodle.
7+
Please let us know which option you choose by filling out the following [survey](https://moodle.zhaw.ch/mod/choice/view.php?id=1539895) on Moodle.
108

119
## Option 1: Tracking App
1210

@@ -35,7 +33,7 @@ Tracking Methods
3533

3634
:::
3735

38-
Please check after a view days if the tracking is working properly. If you have any issues during installation or you are not able to track yourself after the installtion please get in contact with [Nils](mailto:rata@zhaw.ch) or [Dominic](mailto:luoe@zhaw.ch).
36+
Please check after a view days if the tracking is working properly. If you have any issues during installation or you are not able to track yourself after the installtion [please get in contact with us](mailto:terz@zhaw.ch).
3937

4038
***If, however, for privacy reasons, you dont want to use a Tracking App we can hand out a GPS tracker to you.***
4139

@@ -45,4 +43,4 @@ You can use a GPS tracker, provided by our research group. By using a GPS tracke
4543

4644
The drawback off this option is, that in order to retreave the data, you need to bring the tracker to us. Also more manual preprocessing is necessary when preparing your data for the project.
4745

48-
If you choose this option please send us a quick [E-Mail](mailto:luoe@zhaw.ch) so we can arrange the handover of the GPS tracker. You can get the tracker in our office GC 134 at the [Campus Grüental, Wädenswil](https://goo.gl/maps/xDvGFMBEvwBMdWiz7).
46+
If you choose this option please send us a quick [E-Mail](mailto:terz@zhaw.ch) so we can arrange the handover of the GPS tracker. You can get the tracker in our office GC 134 at the [Campus Grüental, Wädenswil](https://goo.gl/maps/xDvGFMBEvwBMdWiz7).

Unterrichtsunterlagen.Rproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 43cdd95c-d3cc-4093-bf7c-a93f64fb3a17
23

34
RestoreWorkspace: No
45
SaveWorkspace: No
@@ -14,8 +15,6 @@ LaTeX: pdfLaTeX
1415

1516
BuildType: Website
1617

17-
PythonType:
18-
PythonVersion:
19-
PythonPath: .
20-
2118
SpellingDictionary: en_GB
19+
20+
ProjectName: CMA - FS25

Week1/2_tasks_and_inputs.qmd

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ Before starting with the task:
1010

1111
1. Make sure you have read and followed the instructions in section [Preparation](#w0-preparation)
1212
2. In RStudio, open the RStudio Project you created for this week. You can see that you are in an RStudio Project if the project's name is visible next to the little RStudio logo in the top right corner of RStudio (otherwise it will read `Project: (None)`).
13-
3. Download the wild boar movement data here: [wildschwein_BE.csv](https://moodle.zhaw.ch/mod/folder/view.php?id=1192125)
13+
3. Download the wild boar movement data from [moodle](https://moodle.zhaw.ch/) (*RStuff**Datasets*)
1414

1515

1616

1717
### Task 1: Import data
1818

1919
Move the file `wildschwein_BE.csv` into your project directory and import it into `r` as a `data.frame`. Assign correct column types as necessary and make sure the time zone is set correctly for the date/time column.
2020

21-
Note: We recommend using the `readr` package to import data (see @sec-readr). These functions have an underscore in their name, e.g. `read_delim` in oppose to the base `R` functions, which have a period (e.g. `read.delim`). Specifically for the wild boar data, we recommend `read_delim()`.
2221

22+
:::{.callout-note}
23+
24+
## `read.delim` vs. `read_delim`
25+
26+
We recommend using the `readr` package to import data (see @sec-readr). These functions have an underscore in their name, e.g. `read_delim` in oppose to the base `R` functions, which have a period (e.g. `read.delim`).
27+
28+
:::
2329

2430

2531
```{r}
@@ -65,6 +71,8 @@ wildschwein_BE_sf <- st_as_sf(wildschwein_BE,
6571
)
6672
```
6773

74+
<br class="br">
75+
6876
Notice how `st_as_sf` takes the EPSG code for the `crs =` argument. You can find a lot of useful information on Coordinate Reference Systems (including EPSG Codes, etc.) under [epsg.io](http://epsg.io).
6977
Let's compare our original `data.frame` with this new `sf` object:
7078

@@ -77,6 +85,10 @@ wildschwein_BE
7785
wildschwein_BE_sf
7886
```
7987

88+
:::{.br}
89+
:::
90+
91+
8092
As you can see, `st_as_sf()` has added some metadata to our dataframe (`Geometry type`, `Dimension`, `Bounding box`, `Geodetic CRS`) and replaced the columns `Lat` and `Long` with a column named `geometry`. Other than that, the new `sf` object is very similar to our original dataframe. In fact, `sf` objects *are* essentially `dataframes`, as you can verify with the function `is.data.frame()`:
8193

8294
```{r}
@@ -86,6 +98,7 @@ is.data.frame(wildschwein_BE_sf)
8698
```
8799

88100
All operations we know from handling `data.frames` can be used on the `sf` object. Try some out!
101+
89102
```{r}
90103
#| echo: true
91104
#| results: "hide"
@@ -98,6 +111,9 @@ wildschwein_BE_sf[wildschwein_BE_sf$TierName == "Sabi", ]
98111
wildschwein_BE_sf[, 2:3]
99112
```
100113

114+
:::{.br}
115+
:::
116+
101117
Instead of keeping the same data twice (once as a `data.frame`, and once as an `sf` object), we will overwrite the `data.frame` and continue working with the `sf` object from now on. This saves some memory space in `R` and avoids confusion.
102118

103119
```{r}
@@ -126,6 +142,7 @@ So what can we do with our new `sf` object that we couldn't before? One example
126142
```
127143

128144
Here's the resulting `sf` object from the operation:
145+
129146
```{r}
130147
#| echo: true
131148
@@ -137,6 +154,9 @@ wildschwein_BE
137154

138155
Transforming from one Coordinate Reference System to another was one operation where we needed an object with a spatial nature. In this way, we were able to use an off-the-shelf function to project the coordinates from one CRS to another. In our next example, we again rely on a spatial function: We want to calculate a [convex hull](https://en.wikipedia.org/wiki/Convex_hull) per Wild boar. And guess what the function for calculating a convex hull is called in `sf`? If you guessed `st_convex_hull()`, you were right!
139156

157+
:::{.br}
158+
:::
159+
140160
By default `st_convex_hull()` calculates the convex hull *per feature*, i.e. *per point* in our dataset. This of course makes little sense. In order to calculate the convex hull per animal, we need to convert our point- to multipoint-features where each feature contains all positions of one animal. This is achieved in two steps:
141161

142162
First: add a grouping variable to the `sf` object. Note the new grouping variable in the metadata of the `sf` object. Other than that, `group_by` has no effect on our `sf` object.
@@ -151,6 +171,10 @@ wildschwein_BE_grouped <- group_by(wildschwein_BE, TierID)
151171
wildschwein_BE_grouped
152172
```
153173

174+
175+
:::{.br}
176+
:::
177+
154178
Second: use `summarise()` to "dissolve" all points into a multipoint object.
155179

156180
```{r}
@@ -179,7 +203,7 @@ Using base plot to visualize `sf` objects is easy enough, just try the following
179203
plot(mcp)
180204
```
181205

182-
But since we use `ggplot` extensively, try and plot the object `mcp` with `ggplot`. Hint: Use the layer `geom_sf()` to add an `sf` object.
206+
One wildboar is seems to be hidden by one of the others. Try and plot the object `mcp` with `ggplot`, setting the layer's `alpha`
183207
Note: `ggplot` refuses to use our specified CRS, so we need to force this by specifying `datum = ` in `coord_sf()`. Try it out.
184208

185209
```{r}
@@ -190,60 +214,28 @@ Note: `ggplot` refuses to use our specified CRS, so we need to force this by spe
190214
```
191215

192216

193-
### Input: Importing raster data {#w1-importing-raster}
194-
195-
In the next task, we would like to add a background map to our `mcp` object. Download the file here: [pk100_BE.tif](https://moodle.zhaw.ch/mod/folder/view.php?id=1192125)
196-
To import the file into `R`, we use the package `terra` with the function `rast`.
197-
198-
```{r}
199-
#| echo: true
200-
201-
library("terra")
202-
203-
pk100_BE <- terra::rast("datasets/pk100_BE.tif")
204-
205-
pk100_BE
206-
```
207-
208-
`pk100_BE_2056.tif` is a three layered geotiff File. The above console output shows some metadata including the resolution, extent and the names of our layers (`pk1_1`, `pk1_2`etc). With the default `plot` method, each layer is displayed individually:
209-
210-
```{r}
211-
#| echo: true
212-
213-
plot(pk100_BE)
214-
```
217+
### Task 5: Making maps with `tmap`
215218

216-
With `plotRGB` all three layers are combined into a single image:
217-
218-
```{r}
219-
plotRGB(pk100_BE)
220-
```
221-
222-
### Task 5: Adding a background map
223-
224-
There are multiple ways to add a background map in `ggplot`, many require additional packages. This is a good opportunity to get to know a completely different package for creating maps: `tmap` ("thematic map"). This package was developed with a syntax very similar to `ggplot2`, which makes it easy to learn.
219+
Let's get to know a completely different package for creating maps: `tmap` ("thematic map"). This package was developed with a syntax very similar to `ggplot2`, which makes it easy to learn.
225220

226221
```{r}
227222
#| echo: true
228223
229224
library("tmap")
230225
231-
tm_shape(pk100_BE) +
232-
tm_rgb()
226+
tm_shape(wildschwein_BE) +
227+
tm_dots(fill = "TierName")
233228
```
234229

235-
As you can see, plotting layers in `tmap` is combined with the `+` sign, just as in `ggplot2`. In `tmap` however, each layer consists of two objects: a `tm_shape()` in which the data is called, and a `tm_*` object in which we define how the data is visualized (`tm_rgb()` states that it is plotted as an RGB Raster Layer). Add the object `mcp` to the plot in this manner. Read [the vignette](https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html) if you are having trouble.
230+
As you can see, plotting layers in `tmap` is combined with the `+` sign, just as in `ggplot2`. In `tmap` however, each layer consists of two objects: a `tm_shape()` in which the data is called, and a `tm_*` object in which we define how the data is visualized (`tm_dots()` states that it is plotted as a point layer).
236231

232+
Add the object `mcp` to the plot in this manner. Checkout the [tmap website](https://r-tmap.github.io/tmap/) if you are having trouble.
237233

238-
```{r}
239-
#| file: "solutions/week1/task_5.R"
240-
#| echo: false
241234

242-
```
243235

244236
### Task 6: Create an interactive map
245237

246-
Rerun the `tmap()...` command from the previous task, but switch the plotting mode to "view"" (`tmap_mode("view")`) beforehand. Omit the raster layer (`pk100_BE`), you won't be needing it.
238+
Rerun the `tmap()...` command from the previous task, but switch the plotting mode to "view"" (`tmap_mode("view")`) beforehand.
247239

248240

249241
```{r}

Week5/2_tasks_and_inputs.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# source("01_R_Files/helperfunctions.R")
77
```
88

9-
Up to now, we have used a variety of different functions designed by other developers. Sometimes we need to execute an operation multiple times, and most often it is reasonable to write a function to do so. Whenever you have copied and pasted a block of code more than twice, you should consider writing a function [@wickham2017].
9+
Up to now, we have used a variety of different functions designed by other developers. Sometimes we need to execute an operation multiple times, and most often it is reasonable to write a function to do so. Whenever you have copied and pasted a block of code more than twice, you should consider writing a function [@wickham2023].
1010

1111
The first step in writing a function, is picking a name and assigning `<- function(){}` to it.
1212

0 commit comments

Comments
 (0)