Skip to content

Commit

Permalink
Update evaluateRM_help.R
Browse files Browse the repository at this point in the history
adapted to only use 'base' packages
  • Loading branch information
PinkertS authored Nov 14, 2024
1 parent 5c58871 commit bc29931
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions inst/examples/evaluateRM_help.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,30 @@ legend("bottomright",

## Compare sensitivity and precision outputs ##
# Calculate overall performance (e.g. mean sensitivity & precision)
res1km$df_eval$Mean_SenPrec <- (res1km$df_eval$Sen_ecoRM+res1km$df_eval$Prec_ecoRM)/2
res10km$df_eval$Mean_SenPrec <- (res10km$df_eval$Sen_ecoRM+res10km$df_eval$Prec_ecoRM)/2
res1km$df_eval$Mean_SenPrec <- (res1km$df_eval$Sen_ecoRM + res1km$df_eval$Prec_ecoRM) / 2
res10km$df_eval$Mean_SenPrec <- (res10km$df_eval$Sen_ecoRM + res10km$df_eval$Prec_ecoRM) / 2

# Combine the data frames and add a resolution column
combined_df <- bind_rows(
res1km$df_eval %>% mutate(Resolution = "1km"),
res10km$df_eval %>% mutate(Resolution = "10km")
# Combine the data frames and add a Resolution column
combined_df <- rbind(
cbind(res1km$df_eval, Resolution = "1km"),
cbind(res10km$df_eval, Resolution = "10km")
)

# Convert to long format
variables <- c("Sen_ecoRM", "Prec_ecoRM", "Mean_SenPrec")
long_df <- data.frame(
Variable = rep(variables, each = nrow(combined_df)),
Value = unlist(combined_df[variables]),
Resolution = rep(combined_df$Resolution, times = length(variables))
)

# Gather data into long format
long_df <- combined_df %>%
select(Sen_ecoRM, Prec_ecoRM, Mean_SenPrec, Resolution) %>%
pivot_longer(cols = c(Sen_ecoRM, Prec_ecoRM, Mean_SenPrec),
names_to = "Variable", values_to = "Value")
# Plot boxplots using base R
boxplot(Value ~ Variable + Resolution, data = long_df,
col = c("#FFC300", "#619CFF"),
names = rep(variables, 2),
xlab = "Variable", ylab = "Value", las = 1,
main = "Boxplot of Sen_ecoRM and Prec_ecoRM")

## Plot results for different range data resolutions ##
# Sensitivity increases and precision decreases with increasing resolution
# Overall performance is slightly higher at more coarse grain
ggplot(long_df, aes(x = Variable, y = Value, fill = Resolution)) +
geom_boxplot() +
labs(x = "Variable", y = "Value", title = "Boxplot of Sen_ecoRM and Prec_ecoRM") +
scale_fill_manual(values = c("10km" = "#619CFF", "1km" = "#FFC300")) +
theme_minimal()
# Adding legend for colors
legend("bottomright", legend = c("1km", "10km"), fill = c("#FFC300", "#619CFF"),
title = "Resolution", bty = "n")

0 comments on commit bc29931

Please sign in to comment.