ToonVanDaele / trias-test

test repository ofr trias
0 stars 0 forks source link

Code for ranking #4

Closed damianooldoni closed 4 years ago

damianooldoni commented 5 years ago

Once we have a value per indicator (and per year), we apply this ranking (as described in https://github.com/trias-project/indicators/issues/49#issuecomment-509530528):

# Ranking
ranking_df <- 
  result_indicator_df %>%
  # to spread number of occurrence indicator values per year
  select(-aoo) %>%
  spread(key = eyear, value = occ, sep = "occ_") %>%
  left_join(result_indicator_df %>%
              # to spread AOO indicator values per year
              select(-occ) %>%
              spread(key = eyear, value = aoo, sep = "aoo_"),
            by = c("taxonKey", "canonicalName")) %>%
  rename_at(vars(starts_with("eyear")), ~str_remove(., pattern = "eyear")) %>%
  group_by(taxonKey, canonicalName) %>%
  arrange(
          desc(aoo_2017), 
          desc(occ_2017), 
          desc(aoo_2016), 
          desc(occ_2016), 
          desc(aoo_2015), 
          desc(occ_2015)) %>%
  select(taxonKey, canonicalName, 
         aoo_2017, occ_2017,
         aoo_2016, occ_2016,
         aoo_2015, occ_2015)

This code results in the ranking here below, based on the test data (19 species):

ranking_testdata

So, you can read the ranking from left to right, like :1st_place_medal: :2nd_place_medal: :3rd_place_medal: ... up to 6th place "medal" at Olympic Games.

damianooldoni commented 4 years ago

@ToonVanDaele : you can close it if you managed to rework it in your code... :+1:

ToonVanDaele commented 4 years ago

This suggestion is implemented in the code. Thanks!