Skip to content

Commit

Permalink
add sac graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderDevisscher committed Jun 16, 2020
1 parent f32a95d commit 77bd97f
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions R-scripts/all_species_dashboard.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,114 @@ renderPlot({
Emergence Graphs - SAC's
==========================================

row
---------------------

### Occupancy
```{r, eval=TRUE, context="server"}
renderPlot({
spec_ind_sub <- spec_ind %>%
filter(gbifapi_acceptedScientificName == input$species)
df_key <- df_ts_compact %>%
filter(taxonKey %in% spec_ind_sub$gbifapi_acceptedKey & year <= maxjaar)
if(nrow(df_key) > 0){
gam_occupancy <- tryCatch(apply_gam(
df = df_key,
y_var = "sac_ncells",
eval_years = max(df_key$year),
type_indicator = "occupancy",
verbose = TRUE,
saveplot = FALSE,
y_label = "occupancy (km2)"
), warning = function(w){"error"})
}else{
gam_occupancy <- "empty"
}
if(gam_occupancy == "error"){
alt_plot <- df_key %>%
ggplot(aes(x = year, y = sac_ncells)) +
ylab("occupancy (km2)") +
geom_point(stat = "identity") +
annotate("text", x = max(df_key$year), y = max(df_key$ncells), label = paste0("The emergence status of \n", input$species, " \n cannot be assessed."),vjust = "inward", hjust = "inward", colour = "red")
print(alt_plot)
}
if(gam_occupancy == "empty"){
alt_plot_2 <- df_key %>%
ggplot(aes(x = year, y = sac_ncells)) +
ylab("occupancy (km2)") +
geom_point(stat = "identity") +
annotate("text", x = maxjaar, y = 1, label = paste0(input$species, " \n is not yet present \n in Belgium"),vjust = "inward", hjust = "inward", colour = "red")
print(alt_plot_2)
}
if(gam_occupancy != "error" & gam_occupancy != "empty"){
print(gam_occupancy$plot)
}
})
```

### Occupancy - corrected
```{r, eval=TRUE, context="server"}
renderPlot({
spec_ind_sub <- spec_ind %>%
filter(gbifapi_acceptedScientificName == input$species)
df_key <- df_ts_compact %>%
filter(taxonKey %in% spec_ind_sub$gbifapi_acceptedKey & year <= maxjaar)
if(nrow(df_key) > 0){
gam_occupancy <- tryCatch(apply_gam(
df = df_key,
y_var = "sac_ncells",
eval_years = max(df_key$year),
type_indicator = "occupancy",
baseline_var = "c_sac_ncells",
verbose = TRUE,
saveplot = FALSE,
y_label = "occupancy (km2)"
), warning = function(w){"error"})
}else{
gam_occupancy <- "empty"
}
if(gam_occupancy == "error"){
alt_plot <- df_key %>%
ggplot(aes(x = year, y = ncells)) +
ylab("occupancy (km2)") +
geom_point(stat = "identity") +
annotate("text", x = max(df_key$year), y = max(df_key$ncells), label = paste0("The emergence status of \n", input$species, " \n cannot be assessed."),vjust = "inward", hjust = "inward", colour = "red")
print(alt_plot)
}
if(gam_occupancy == "empty"){
alt_plot_2 <- df_key %>%
ggplot(aes(x = year, y = ncells)) +
ylab("occupancy (km2)") +
geom_point(stat = "identity") +
annotate("text", x = maxjaar, y = 1, label = paste0(input$species, " \n is not yet present \n in Belgium"),vjust = "inward", hjust = "inward", colour = "red")
print(alt_plot_2)
}
if(gam_occupancy != "error" & gam_occupancy != "empty"){
print(gam_occupancy$plot)
}
})
```

Emergence Graphs - SPA's
==========================================

Expand Down

0 comments on commit 77bd97f

Please sign in to comment.