# task_1.R
################################################################################
library("readr") # move this to the top of your script
# Data import ####
<- read_delim("datasets/wildschwein_BE.csv", ",")
wildschwein_BE
# Check Timezone
attr(wildschwein_BE$DatetimeUTC, "tzone") # or
$DatetimeUTC[1]
wildschwein_BE
# task_2.R
################################################################################
library("ggplot2") # move this to the top of your script
ggplot(wildschwein_BE, aes(Long, Lat, colour = TierID)) +
geom_point() +
theme(legend.position = "none")
# task_3.R
################################################################################
library("sf") # move this to the top of your script
# Input: Handling spatial data
<- st_as_sf(wildschwein_BE,
wildschwein_BE coords = c("Long", "Lat"),
crs = 4326
)
<- st_transform(wildschwein_BE, 2056)
wildschwein_BE
# task_4.R
################################################################################
library("dplyr") # move this to the top of your script
<- group_by(wildschwein_BE, TierID)
wildschwein_BE_grouped
<- summarise(wildschwein_BE_grouped)
wildschwein_BE_smry
<- st_convex_hull(wildschwein_BE_smry)
mcp
ggplot(mcp, aes(fill = TierID)) +
geom_sf(alpha = 0.4)
ggplot(mcp, aes(fill = TierID)) +
geom_sf(alpha = 0.4) +
coord_sf(datum = 2056)
# task_5.R
################################################################################
library("tmap") # move this to the top of your script
# Input: Importing raster data
library("terra") # move this to the top of your script
<- terra::rast("datasets/pk100_BE.tif")
pk100_BE
<- st_convex_hull(wildschwein_BE_smry)
mcp
tm_shape(pk100_BE) +
tm_rgb() +
tm_shape(mcp) +
tm_polygons(col = "TierID", alpha = 0.4, border.col = "red") +
tm_legend(bg.color = "white")
# task_6.R
################################################################################
tmap_mode("view")
tm_shape(mcp) +
tm_polygons(col = "TierID", alpha = 0.4, border.col = "red") +
tm_legend(bg.color = "white")
Solutions
Tip
Hover over the code and copy the content by clicking on the clipboard icon on the top right. You can now paste this into an R-Script.