exercise_5

BMI <- function(height, weight) {
    BMI_calc <- weight / (height)^2
    print(paste("Your BMI is", BMI_calc))
}

BMI(1.75, 65)
[1] "Your BMI is 21.2244897959184"
Deg_Far <- function(celsius) {
  return(celsius * 9/5 + 32)
}

Deg_Far(35)
[1] 95
eucl_dist <- function(x1, x2, y1, y2) {
  sqrt((x1 - x2)^2 + (y1 - y2)^2)
}

eucl_dist(1, 5, 8, 2)
[1] 7.211103
library(ggplot2)
library(readr)
library("sf")
library(dplyr)
library(lubridate)

wildschwein_BE <- read_delim("data/wildschwein_BE_2056.csv")


ggplot(wildschwein_BE, aes(E, N, colour = TierID))+
  geom_point()

wildschwein_filter <- wildschwein_BE |> 
  filter(TierName %in% c("Rosa", "Sabi"),
    DatetimeUTC >= ("2015-04-01 00:00:00"),
    DatetimeUTC <= ("2015-04-15 23:59:59"))

wildschwein_filter <- wildschwein_filter |>
  mutate(
    DatetimeUTC_15 = round_date(DatetimeUTC, unit = "15 minutes")
  )
rosa <- wildschwein_filter |> 
  filter(TierName == "Rosa")

sabi <- wildschwein_filter |> 
  filter(TierName == "Sabi")


joined <- inner_join(rosa, sabi, by = "DatetimeUTC_15", suffix = c("_Rosa", "_Sabi"))

joined <- joined |>
  mutate(distance = eucl_dist(E_Rosa, E_Sabi, N_Rosa, N_Sabi))


joined <- joined |>
  mutate(meet = distance <= 100)
meets <- joined |> 
  filter(meet == TRUE)

ggplot() +
  geom_point(data = rosa, aes(E, N, fill = "Rosa"),
             colour = "red", alpha = 0.3, size = 2) +
  geom_point(data = sabi, aes(E, N, fill = "Sabi"), 
             colour = "blue", alpha = 0.3, size = 2) +
  geom_point(data = meets, aes(E_Rosa, N_Rosa, fill = "Rosa"),shape = 21, color = "black", fill = "red", alpha = 0.5, stroke = 0.8, size = 2) +
  geom_point(data = meets,aes(E_Sabi, N_Sabi, fill = "Sabi"),shape = 21, color = "black", fill = "blue", alpha = 0.5, stroke = 0.8, size = 2)+
  labs(x = "E", y = "N") +
  theme_minimal()