R and Shiny Training: If you find this blog to be interesting, please note that I offer personalized and group-based training sessions that may be reserved through Buy me a Coffee. Additionally, I provide training services in the Spanish language and am available to discuss means by which I may contribute to your Shiny project.
Updated 2023-07-05: Reflects changes in the freedomhouse package.
Motivation
As an update to Tidying the Freedom Index, I organized the final result as an R package, with the idea of making it easier to use the data in other projects.
The package is available at GitHub. The package is not available at CRAN, but you can install it from GitHub using the following code:
# install.packages("remotes")
remotes::install_github("pachadotdev/freedomhouse")
Demonstration
Let’s see how the package works. First, we load dplyr and freedomhouse package and the data.
if (!require(dplyr)) install.packages("dplyr")
if (!require(remotes)) install.packages("remotes")
if (!require(freedomhouse)) remotes::install_github("pachadotdev/freedomhouse")
── R CMD build ─────────────────────────────────────────────────────────────────
* checking for file ‘/tmp/RtmpquGXJD/remotes1b97cb5cf9ffc7/pachadotdev-freedomhouse-6f48484/DESCRIPTION’ ... OK
* preparing ‘freedomhouse’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘freedomhouse_0.4.0.tar.gz’
library(dplyr)
library(freedomhouse)
Now we search for “trade union” in the sub_item_description column.
country_score %>%
filter(grepl("trade union", sub_item_description)) %>%
distinct(sub_item_description)
# A tibble: 1 × 1
sub_item_description
<fct>
1 Is there freedom for trade unions and similar professional or labor organizat…
Now we know that “E3” is the question about trade unions. Let’s see the question.
country_score %>%
filter(sub_item == "E3") %>%
distinct(sub_item_description) %>%
pull()
[1] Is there freedom for trade unions and similar professional or labor organizations?
25 Levels: Was the current head of government or other chief national authority elected through free and fair elections? ...
As an example, we can filter by sub-item code and country code for trade unions in Canada
unions_canada <- country_score %>%
filter(
sub_item == "E3",
iso3c == "CAN"
) %>%
inner_join(
country_rating_text %>%
select(year, iso3c, sub_item, detail) %>%
filter(
sub_item == "E3",
iso3c == "CAN"
),
by = c("year", "iso3c", "sub_item")
) %>%
select(year, iso3c, sub_item, score, detail)
unions_canada
# A tibble: 7 × 5
year iso3c sub_item score detail
<int> <fct> <fct> <int> <fct>
1 2023 CAN E3 4 Trade unions and business associations enjoy high …
2 2022 CAN E3 4 Trade unions and business associations enjoy high …
3 2021 CAN E3 4 Trade unions and business associations enjoy high …
4 2020 CAN E3 4 Trade unions and business associations enjoy high …
5 2019 CAN E3 4 Trade unions and business associations enjoy high …
6 2018 CAN E3 4 Trade unions and business associations enjoy high …
7 2017 CAN E3 4 Trade unions and business associations enjoy high …
Even more, we can print the justifications and see why Canada obtained the maximum score in that item (see the methodology).
unions_canada %>%
distinct(detail) %>%
pull()
[1] Trade unions and business associations enjoy high levels of membership and are well organized.
[2] Trade unions and business associations enjoy high levels of membership and are well organized. In June 2017, the new Liberal government reversed two controversial labor laws approved by the previous government. The laws had been criticized by unions for putting in place onerous financial disclosure rules, and making it more difficult to organize new unions in federally regulated sectors.
29256 Levels: Afghanistan's political rights rating improved from 6 to 5 due to increased opposition political activity ahead of scheduled elections, as well as modest gains in government transparency. ...