Skip to content

Commit

Permalink
Update format
Browse files Browse the repository at this point in the history
  • Loading branch information
markus1bauer committed Mar 2, 2022
1 parent 18c9473 commit e7037f8
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 85 deletions.
25 changes: 25 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/
15 changes: 15 additions & 0 deletions .github/workflows/check_source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
push:
branches-ignore:
- gh-pages

name: check-source

jobs:
check-src:
runs-on: ubuntu-latest
name: "Check coding style"
steps:
- uses: inbo/actions/check_src@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion R/_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ library(EMLassemblyline)

### Start ###
rm(list = ls())
setwd(here("data/raw"))
setwd(here("data", "raw"))



Expand Down
17 changes: 12 additions & 5 deletions R/_prepare_data_spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ sites <- read_csv(here("data", "raw", "data_raw_sites.csv"),
exposition = "f"
)
) %>%
select(id, location, longitude, latitude, constructionYear, sandPerc, phosphorus, phosphorusClass) %>%
select(id, location, longitude, latitude, constructionYear, sandPerc,
phosphorus, phosphorusClass) %>%
mutate(
plot = str_sub(id, start = 1, end = 2),
locationAbb = str_sub(location, 1, 3),
Expand All @@ -62,9 +63,14 @@ rm(coord)
#### Calculate center of locations ###
locations <- sites_basic %>%
group_by(locationYear) %>%
summarise(across(c(longitude, latitude, constructionYear), mean, na.rm = TRUE)) %>%
summarise(across(c(longitude, latitude, constructionYear),
mean, na.rm = TRUE)) %>%
rename(longitude_center = longitude, latitude_center = latitude)
sites_basic <- left_join(sites_basic, locations %>% select(-constructionYear), by = "locationYear")
sites_basic <- left_join(
sites_basic,
locations %>% select(-constructionYear),
by = "locationYear"
)


## 2 Transform shp files ################################################
Expand Down Expand Up @@ -103,7 +109,8 @@ st_intersection(bbox) # problem
# plot(st_geometry(danube_isar))
# rm(data)
### Here the digitized file ###
danube_isar <- st_read(here("data", "raw", "spatial", "danube_isar_digitized_epsg4326.shp"))
danube_isar <- st_read(here("data", "raw", "spatial",
"danube_isar_digitized_epsg4326.shp"))


## 4 Background map #####################################################
Expand Down Expand Up @@ -208,7 +215,7 @@ st_write(dikes,
dsn = here("data", "processed", "spatial")
)
st_write(conservation_area,
layer = "conservation_area_epsg4326.shp", driver = "ESRI Shapefile", delete_layer = T,
layer = "conservation_area_epsg4326.shp", driver = "ESRI Shapefile", delete_layer = TRUE,
dsn = here("data", "processed", "spatial")
)
st_write(ffh_area,
Expand Down
45 changes: 29 additions & 16 deletions R/_prepare_data_vegetation.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ remotes::install_github(file.path("inbo", "checklist"))
### Start ###
# installr::updateR(browse_news = FALSE, install_R = TRUE, copy_packages = TRUE, copy_Rprofile.site = TRUE, keep_old_packages = TRUE, update_packages = TRUE, start_new_R = FALSE, quit_R = TRUE, print_R_versions = TRUE, GUI = TRUE)
# sessionInfo()
checklist::setup_source()
checklist::check_source()
devtools::check()
#checklist::setup_source()
#checklist::check_source()
#devtools::check()

rm(list = ls())
setwd(here("data", "raw"))
Expand Down Expand Up @@ -232,12 +232,12 @@ rm(list = ls(pattern = "[^species|traits|sites]"))



#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# B Create variables ############################################################
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# B Create variables ###########################################################
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


## 1 Create simple variables ####################################################
## 1 Create simple variables ###################################################

traits <- traits %>%
mutate(
Expand Down Expand Up @@ -271,7 +271,7 @@ sites <- sites %>%
)


## 2 Coverages ######################################################################
## 2 Coverages #################################################################

cover <- left_join(species, traits, by = "name") %>%
select(
Expand Down Expand Up @@ -947,7 +947,9 @@ eigenvals <- pca %>%
summary() %>%
as_tibble() %>%
select(PC1:PC3) %>%
bind_cols(c("Eigenvalues", "Proportion Explained", "Cumulative Proportion")) %>%
bind_cols(c("Eigenvalues",
"Proportion Explained",
"Cumulative Proportion")) %>%
rename("variables" = "...4") %>%
mutate(across(where(is.numeric), as.double))
values <- pca %>%
Expand Down Expand Up @@ -989,7 +991,8 @@ rm(list = setdiff(ls(), c("sites", "species", "traits", "pcaSoil")))
### b Climate PCA -----------------------------------------------------

### * Temperature ####
data <- read_csv(here("data", "raw", "temperature", "data", "data_OBS_DEU_P1M_T2M.csv"),
data <- read_csv(here("data", "raw", "temperature", "data",
"data_OBS_DEU_P1M_T2M.csv"),
col_names = TRUE, na = c("", "NA", "na"), col_types =
cols(
.default = "?"
Expand Down Expand Up @@ -1032,7 +1035,9 @@ data <- read_csv(here("data", "raw", "temperature", "data", "data_OBS_DEU_P1M_T2
names_from = season, values_from = seasonMean
) %>%
group_by(year) %>%
summarise(across(where(is.numeric), ~ max(., na.rm = TRUE)), .groups = "keep") %>% # warnings because of lates year (summer, autumn, winter), can be ignored
summarise(across(where(is.numeric), ~ max(., na.rm = TRUE)),
.groups = "keep") %>%
# warnings because of lates year (summer, autumn, winter), can be ignored
mutate(year = factor(year))

sites <- sites %>%
Expand Down Expand Up @@ -1073,7 +1078,8 @@ sites <- sites %>%
)

### * Precipitation ####
data <- read_csv(here("data", "raw", "precipitation", "data", "data_OBS_DEU_P1M_RR.csv"),
data <- read_csv(here("data", "raw", "precipitation", "data",
"data_OBS_DEU_P1M_RR.csv"),
col_names = TRUE, na = c("", "NA", "na"), col_types =
cols(
.default = "?"
Expand Down Expand Up @@ -1120,7 +1126,8 @@ data <- read_csv(here("data", "raw", "precipitation", "data", "data_OBS_DEU_P1M_
.groups = "keep"
) %>%
mutate(currentMean = if_else(season == "spring", currentMean, NA_real_)) %>%
pivot_wider(id_cols = c(year, yearMean, currentMean), names_from = season, values_from = seasonMean) %>%
pivot_wider(id_cols = c(year, yearMean, currentMean),
names_from = season, values_from = seasonMean) %>%
group_by(year) %>%
summarise(across(where(is.numeric), ~ max(., na.rm = TRUE)),
.groups = "keep"
Expand Down Expand Up @@ -1184,7 +1191,9 @@ eigenvals <- pca %>%
summary() %>%
as_tibble() %>%
select(PC1:PC3) %>%
bind_cols(c("Eigenvalues", "Proportion Explained", "Cumulative Proportion")) %>%
bind_cols(c("Eigenvalues",
"Proportion Explained",
"Cumulative Proportion")) %>%
rename("variables" = "...4") %>%
mutate(across(where(is.numeric), as.double))
values <- pca %>%
Expand Down Expand Up @@ -1248,7 +1257,9 @@ eigenvals <- pca %>%
summary() %>%
as_tibble() %>%
select(PC1:PC3) %>%
bind_cols(c("Eigenvalues", "Proportion Explained", "Cumulative Proportion")) %>%
bind_cols(c("Eigenvalues",
"Proportion Explained",
"Cumulative Proportion")) %>%
rename("variables" = "...4") %>%
mutate(across(where(is.numeric), as.double))
values <- pca %>%
Expand All @@ -1266,7 +1277,9 @@ pcaConstuctionYear <- values$species[, 1:3] %>%
"precMean_constructionYear", "precSpring_constructionYear",
"precSummer_constructionYear", "precAutumn_constructionYear",
"precWinter_constructionYear",
"precMean_constructionYearPlus", "precSpring_constructionYearPlus", "precSummer_constructionYearPlus", "precAutumn_constructionYearPlus", "precWinter_constructionYearPlus"
"precMean_constructionYearPlus",
"precSpring_constructionYearPlus", "precSummer_constructionYearPlus",
"precAutumn_constructionYearPlus", "precWinter_constructionYearPlus"
)) %>%
rename(variables = "...4") %>%
bind_rows(eigenvals)
Expand Down
19 changes: 11 additions & 8 deletions R/show_figure_1_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ setwd(here("data", "processed", "spatial"))

### Load data ###
germany <- st_read("germany_epsg4326.shp")
danube <- st_read(here("data", "raw", "spatial", "danube_isar_digitized_epsg4326.shp"))
danube <- st_read(here("data", "raw", "spatial",
"danube_isar_digitized_epsg4326.shp"))
danube$river[2] <- "Isar"
filter <- read_csv(here("data", "processed", "data_processed_sites_spatial.csv"),
filter <- read_csv(here("data", "processed",
"data_processed_sites_spatial.csv"),
col_names = TRUE, na = c("na", "NA"), col_types =
cols(
.default = "?"
Expand All @@ -46,7 +48,7 @@ conservation_area <- st_read("conservation_area_epsg4326.shp")
ffh_area <- st_read("ffh_area_epsg4326.shp")
dikes <- st_read("dikes_epsg4326.shp")
locations <- read_csv("locations.csv",
col_names = T, col_types =
col_names = TRUE, col_types =
cols(
locationYear = "f"
)
Expand Down Expand Up @@ -138,7 +140,7 @@ graphSites + inset_element(graphGermany,
bottom = .65,
right = .99,
top = .99,
on_top = T
on_top = TRUE
)


Expand Down Expand Up @@ -198,7 +200,7 @@ graphSites + inset_element(graphGermany,
bottom = .65,
right = .99,
top = .99,
on_top = T
on_top = TRUE
)

### c Save --------------------------------------------------------------
Expand Down Expand Up @@ -227,10 +229,10 @@ tmap <- tm_shape(danube) +
tm_dots(col = "red", size = .2, shape = 16) +
tm_compass(position = c("left", "bottom"), size = 2) +
tm_scale_bar(position = c("left", "bottom", with = 0.4)) +
tm_layout(frame = F)
tm_layout(frame = FALSE)
tmap_ger <- tm_shape(germany) +
tm_borders(col = "black") +
tm_layout(frame = F)
tm_layout(frame = FALSE)

### b Save --------------------------------------------------------------

Expand All @@ -242,6 +244,7 @@ tmap_save(tmap,
width = unit(3, "cm"),
height = unit(4, "cm")
),
filename = paste0(here("outputs", "figures"), "/", "figure_1_map_tmap_300dpi_8x11cm.tiff"),
filename = paste0(here("outputs", "figures"), "/",
"figure_1_map_tmap_300dpi_8x11cm.tiff"),
dpi = 300
)
19 changes: 14 additions & 5 deletions R/show_figure_2a_comparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ theme_mb <- function() {
panel.background = element_rect(fill = "white"),
text = element_text(size = 9, color = "black"),
strip.text = element_text(size = 10),
axis.text = element_text(angle = 0, hjust = 0.5, size = 9, color = "black"),
axis.title = element_text(angle = 0, hjust = 0.5, size = 9, color = "black"),
axis.text = element_text(angle = 0, hjust = 0.5, size = 9,
color = "black"),
axis.title = element_text(angle = 0, hjust = 0.5, size = 9,
color = "black"),
axis.line = element_line(),
legend.key = element_rect(fill = "white"),
legend.position = "none",
Expand All @@ -75,18 +77,25 @@ theme_mb <- function() {
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


data_model <- ggeffect(m2, type = "emm", c("comparison"), back.transform = TRUE) %>%
data_model <- ggeffect(m2, type = "emm", c("comparison"),
back.transform = TRUE) %>%
mutate(
predicted = exp(predicted),
conf.low = exp(conf.low),
conf.high = exp(conf.high),
cross = if_else(x %in% c("1819"), "filled", "open"),
x = fct_recode(x, "2017 vs 2018" = "1718", "2018 vs 2019" = "1819", "2019 vs 2021" = "1921")
x = fct_recode(x,
"2017 vs 2018" = "1718",
"2018 vs 2019" = "1819",
"2019 vs 2021" = "1921")
)

data <- sites %>%
rename(predicted = y, x = comparison) %>%
mutate(x = fct_recode(x, "2017 vs 2018" = "1718", "2018 vs 2019" = "1819", "2019 vs 2021" = "1921"))
mutate(x = fct_recode(x,
"2017 vs 2018" = "1718",
"2018 vs 2019" = "1819",
"2019 vs 2021" = "1921"))

(graph_a <- ggplot() +
geom_quasirandom(
Expand Down
16 changes: 9 additions & 7 deletions R/show_figure_2b_location.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ m2 <- blmer(log(y) ~ comparison + exposition * PC1soil + PC2soil + PC3soil +
data = sites)

### * Functions ####
theme_mb <- function(){
theme_mb <- function() {
theme(
panel.background = element_rect(fill = "white"),
text = element_text(size = 9, color = "black"),
Expand Down Expand Up @@ -83,26 +83,28 @@ data_model <- ggeffect(m2, type = "emm", c("locationYear"), back.transform = TRU
cross = if_else(x %in% c("PFE-2008", "IRL-2003"), "filled", "open"))

data <- sites %>%
rename(predicted = y, x = locationYear)
rename(predicted = y, x = locationYear)

(graph_b <- ggplot() +
geom_quasirandom(data = data,
geom_quasirandom(data = data,
aes(x = x, predicted),
dodge.width = .6, size = 1, shape = 16, color = "grey70") +
dodge.width = .6, size = 1, shape = 16,
color = "grey70") +
geom_hline(yintercept = c(mean(sites$y),
mean(sites$y) + 0.5 * sd(sites$y),
mean(sites$y) - 0.5 * sd(sites$y)),
linetype = c(1, 2, 2),
color = "grey70") +
geom_errorbar(data = data_model,
aes(x, predicted, ymin = conf.low, ymax = conf.high),
geom_errorbar(data = data_model,
aes(x, predicted, ymin = conf.low, ymax = conf.high),
width = 0.0, size = 0.4) +
geom_point(data = data_model,
aes(x, predicted, shape = cross),
size = 2) +
scale_y_continuous(limits = c(0, .92), breaks = seq(0, 400, .1)) +
scale_shape_manual(values = c("circle", "circle open")) +
labs(x = "", y = expression(Temporal~"beta"~diversity~"["*italic('D')[sor]*"]")) +
labs(x = "",
y = expression(Temporal ~ "beta" ~ diversity ~ "[" * italic("D")[sor] * "]")) +
theme_mb())

### Save ###
Expand Down
Loading

0 comments on commit e7037f8

Please sign in to comment.