diff --git a/R-scripts/all_species_dashboard.Rmd b/R-scripts/all_species_dashboard.Rmd index 682a5a1..d0a6b51 100644 --- a/R-scripts/all_species_dashboard.Rmd +++ b/R-scripts/all_species_dashboard.Rmd @@ -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 ==========================================