Commit 1388ab67 authored by LDalby's avatar LDalby
Browse files

Adapt to show plots with high/low grain-dists

parent e16c5da0
...@@ -49,8 +49,8 @@ bckgr <- readRDS(here("data", "vejlerne-background.rds")) ...@@ -49,8 +49,8 @@ bckgr <- readRDS(here("data", "vejlerne-background.rds"))
fields <- st_read(here("data", "vejlerne-fields.gpkg")) fields <- st_read(here("data", "vejlerne-fields.gpkg"))
# Make base grid ---- # Make base grid ----
sf::st_make_grid(outline, n = c(36000/400, 24000/400)) %>% sf::st_make_grid(outline, n = c(36000/500, 24000/500)) %>%
sf::st_sf(id = 1:5400, .) -> grd sf::st_sf(id = 1:3456, .) -> grd
st_centroid(fields) -> field_centroids st_centroid(fields) -> field_centroids
...@@ -80,22 +80,22 @@ left_join(goose_numbers, grain_dists, by = c("param", "value", "season")) -> goo ...@@ -80,22 +80,22 @@ left_join(goose_numbers, grain_dists, by = c("param", "value", "season")) -> goo
# Mean numbers per day # Mean numbers per day
goose_numbers %>% goose_numbers %>%
mutate(day = day - 365*season) %>% mutate(day = day - 365*season) %>%
select(param, value, season, day, pinkfoot, barnacle, greylag) %>% select(grain_dist, param, value, season, day, pinkfoot, barnacle, greylag) %>%
group_by(param, value, season, day) %>% group_by(grain_dist, param, value, season, day) %>%
summarise_at(.vars = vars(pinkfoot, barnacle, greylag), summarise_at(.vars = vars(pinkfoot, barnacle, greylag),
.funs = funs(daily = sum)) %>% .funs = funs(daily = sum)) %>%
group_by(param, value, day) %>% group_by(grain_dist, param, value, day) %>%
summarise_at(.vars = vars(ends_with("daily")), summarise_at(.vars = vars(ends_with("daily")),
.funs = funs(avg = mean, .funs = funs(avg = mean,
min, max)) %>% min, max)) %>%
ungroup() %>% ungroup() %>%
gather(key = species, value = numbers, -param, -value, -day) %>% gather(key = species, value = numbers, -grain_dist, -param, -value, -day) %>%
filter(numbers > 0) -> numbers_per_day filter(numbers > 0) -> numbers_per_day
numbers_per_day %>% numbers_per_day %>%
filter(value == 1) -> default filter(value == 1) -> default
left_join(numbers_per_day, default, left_join(numbers_per_day, default,
by = c("param", "day", "species"), by = c("grain_dist", "param", "day", "species"),
suffix = c("", "_default")) %>% suffix = c("", "_default")) %>%
mutate(standarized = numbers/numbers_default) -> numbers_per_day mutate(standarized = numbers/numbers_default) -> numbers_per_day
...@@ -111,20 +111,18 @@ numbers_per_day %>% ...@@ -111,20 +111,18 @@ numbers_per_day %>%
subtitle = "Pinkfeet numbers as a function of barnacle numbers", subtitle = "Pinkfeet numbers as a function of barnacle numbers",
caption = "Numbers are average of 10 consecutive seasons", caption = "Numbers are average of 10 consecutive seasons",
y = "proportion of default numbers") + y = "proportion of default numbers") +
facet_grid(~grain_dists) facet_grid(~grain_dist)
goose_numbers %>% goose_numbers %>%
select(param, value, season, pinkfoot, barnacle, greylag) %>% select(grain_dist, param, value, season, pinkfoot, barnacle, greylag) %>%
group_by(param, value, season) %>% group_by(grain_dist, param, value, season) %>%
summarise(pinkfoot = sum(pinkfoot, na.rm = TRUE), summarise(pinkfoot = sum(pinkfoot, na.rm = TRUE),
barnacle = sum(barnacle, na.rm = TRUE), barnacle = sum(barnacle, na.rm = TRUE),
greylag = sum(greylag, na.rm = TRUE)) %>% greylag = sum(greylag, na.rm = TRUE)) %>%
ungroup() %>% ungroup() %>%
gather(key = species, value = numbers, -param, -value, -season) -> numbers_per_season gather(key = species, value = numbers, -grain_dist, -param, -value, -season) -> numbers_per_season
numbers_per_season %>% numbers_per_season %>%
...@@ -132,7 +130,7 @@ numbers_per_season %>% ...@@ -132,7 +130,7 @@ numbers_per_season %>%
ggplot(aes(value, numbers/1e6)) + ggplot(aes(value, numbers/1e6)) +
geom_point(alpha = 0.5) + geom_point(alpha = 0.5) +
geom_smooth() + geom_smooth() +
facet_wrap(~species, scales = "free_y") + facet_grid(species ~ grain_dist, scales = "free_y") +
hrbrthemes::theme_ipsum_rc(axis_title_size = 12) + hrbrthemes::theme_ipsum_rc(axis_title_size = 12) +
labs(title = "Goose days as a function of barnacle goose input numbers", labs(title = "Goose days as a function of barnacle goose input numbers",
y = expression("Goose days" %*% 1e-6), y = expression("Goose days" %*% 1e-6),
...@@ -142,16 +140,16 @@ numbers_per_season %>% ...@@ -142,16 +140,16 @@ numbers_per_season %>%
# Average goose days per season # Average goose days per season
goose_numbers %>% goose_numbers %>%
select(param, value, season, pinkfoot, barnacle, greylag, polyref) %>% select(grain_dist, param, value, season, pinkfoot, barnacle, greylag, polyref) %>%
group_by(param, value, season, polyref) %>% group_by(grain_dist, param, value, season, polyref) %>%
summarise(pinkfoot = sum(pinkfoot, na.rm = TRUE), summarise(pinkfoot = sum(pinkfoot, na.rm = TRUE),
barnacle = sum(barnacle, na.rm = TRUE), barnacle = sum(barnacle, na.rm = TRUE),
greylag = sum(greylag, na.rm = TRUE)) %>% greylag = sum(greylag, na.rm = TRUE)) %>%
group_by(param, value, polyref) %>% group_by(grain_dist, param, value, polyref) %>%
summarise(pinkfoot = mean(pinkfoot, na.rm = TRUE), summarise(pinkfoot = mean(pinkfoot, na.rm = TRUE),
barnacle = mean(barnacle, na.rm = TRUE), barnacle = mean(barnacle, na.rm = TRUE),
greylag = mean(greylag, na.rm = TRUE)) %>% greylag = mean(greylag, na.rm = TRUE)) %>%
gather(key = species, value = numbers, -param, -value, -polyref) %>% gather(key = species, value = numbers, -grain_dist, -param, -value, -polyref) %>%
dplyr::filter(numbers > 0) -> season_goose_numbers dplyr::filter(numbers > 0) -> season_goose_numbers
...@@ -160,7 +158,7 @@ goose_numbers %>% ...@@ -160,7 +158,7 @@ goose_numbers %>%
# the same cell. # the same cell.
left_join(grd_id_polyref, season_goose_numbers, by = "polyref") %>% left_join(grd_id_polyref, season_goose_numbers, by = "polyref") %>%
drop_na() %>% drop_na() %>%
group_by(id, param, value, species) %>% group_by(id, grain_dist, param, value, species) %>%
summarise(goose_days = sum(numbers)) -> gdays summarise(goose_days = sum(numbers)) -> gdays
readRDS(path_desktop("gdays.RDS")) -> gdays readRDS(path_desktop("gdays.RDS")) -> gdays
...@@ -169,7 +167,8 @@ readRDS(path_desktop("gdays.RDS")) -> gdays ...@@ -169,7 +167,8 @@ readRDS(path_desktop("gdays.RDS")) -> gdays
gdays %>% gdays %>%
ungroup() %>% ungroup() %>%
filter(param == "GOOSE_BN_STARTNO_SCALER", filter(param == "GOOSE_BN_STARTNO_SCALER",
species == "barnacle") %>% species == "barnacle",
grain_dist == "high") %>%
select(-param, -species) -> gdays_bn_scaler select(-param, -species) -> gdays_bn_scaler
ggmap(bckgr) + ggmap(bckgr) +
...@@ -184,7 +183,7 @@ ggmap(bckgr) + ...@@ -184,7 +183,7 @@ ggmap(bckgr) +
y = "") + y = "") +
transition_manual(value) -> bn_map transition_manual(value) -> bn_map
animate(bn_map) animate(bn_map)
anim_save(filename = path_desktop("bn.gif")) anim_save(filename = path_desktop("bn-high.gif"))
# Pinkfoot # Pinkfoot
gdays %>% gdays %>%
ungroup() %>% ungroup() %>%
...@@ -244,7 +243,7 @@ ggmap(bckgr) + ...@@ -244,7 +243,7 @@ ggmap(bckgr) +
# Depletion # Depletion
forage %>% forage %>%
select(season, day, grain, maize) %>% select(grain_dist, season, day, grain, maize) %>%
group_by(season, day) %>% group_by(season, day) %>%
summarise(grain = sum(grain), summarise(grain = sum(grain),
maize = sum(maize)) %>% maize = sum(maize)) %>%
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment