Trabajo elaborado para la asignatura “Programación y manejo de datos en la era del Big Data” de la Universitat de València durante el curso 2021-2022. El repo del trabajo está aquí.
La página web de la asignatura y los trabajos de mis compañeros pueden verse aquí.
El Índice de Libertad Económica es elaborado anualmente por la Fundación Heritage y The Wall Street Journal. Su objetivo declarado es medir el nivel de economía de mercado que un país admite. El ranking puntúa datos entre 0 y 100, donde 0 significa «ausencia de libertad económica» y 100 significa «libertad económica total».
Más allá de sus objetivos, está pensado para ayudar a los lectores a realizar un seguimiento de más de dos décadas del avance en la libertad económica, la prosperidad y las oportunidades, y promover estas ideas en sus hogares, escuelas y comunidades. El índice cubre 12 libertades, desde los derechos de propiedad hasta la libertad financiera, en 186 países. En concreto, vamos estudiar el índice para el año 2019, anterior a la pandemia mundial de covid-19.
Descargamos los datos aqui. A continuación, situamos los datos en la carpeta datos y realizamos las siguientes modificaciones:
df <- read.csv("./datos/economic_freedom_index2019_data.csv")
#- ponemos las variables en forma numérica
df <- df %>% arrange(desc(X2019.Score)) %>%
filter(!X2019.Score == 'N/A')
#seleccionamos las variables que nos interesan
df <- df %>%
rename(Score_2019 = "X2019.Score",
GDP_capita = "GDP.per.Capita..PPP.") %>%
select(Country, Region, World.Rank, Region.Rank, Score_2019, Property.Rights, Judical.Effectiveness, Government.Integrity, Business.Freedom, Labor.Freedom, Monetary.Freedom, Trade.Freedom, Financial.Freedom, GDP_capita)
#renombramos paises
df$Country <- recode(df$Country,
"Hong Kong SAR" = "Hong Kong",
"Czech Republic" = "Czech Rep.",
"Korea, South" = "Korea",
"Brunei Darussalam" = "Brunei",
"Slovak Republic" = "Slovakia",
"Cabo Verde" = "Cape Verde",
"Kyrgyz Republic" = "Kyrgyzstan",
"Bosnia and Herzegovina" = "Bosnia and Herz.",
"Dominican Republic" = "Dominican Rep.",
"Lao P.D.R." = "Lao PDR",
"Solomon Islands" = "Solomon Is.",
"São Tomé and Príncipe" = "São Tomé and Principe",
"Burma" = "Myanmar",
"Macau" = "Macao",
"Taiwan" = "Taiwan",
"Saint Vincent and the Grenadines" = "St. Vin. and Gren.",
"Congo, Democratic Republic of the Congo" = "Dem. Rep. Congo",
"Korea, North" = "Dem. Rep. Korea",
"Central African Republic" = "Central African Rep.",
"Equatorial Guinea" = "Eq. Guinea",
"Congo, Republic of" = "Congo",
"Eswatini" = "Swaziland")
df$GDP_capita <- recode(df$GDP_capita,
"$1,700 (2015 est.)" = "$1,700")
#Eliminamos el simbolo del dólar
df <- df %>% mutate(GDP_capita = str_replace(GDP_capita, "\\$", "" ))
#Eliminamos las comas para pasarlo a numerico y las remplazamos por puntos
df <- df %>% mutate(GDP_capita = str_replace(GDP_capita, ",", "" ))
df <- transform(df, Score_2019 = as.numeric(Score_2019),
Property.Rights = as.numeric(Property.Rights),
Judical.Effectiveness = as.numeric(Judical.Effectiveness),
Labor.Freedom = as.numeric(Labor.Freedom),
Financial.Freedom = as.numeric(Financial.Freedom),
GDP_capita = as.numeric(GDP_capita))
#.eliminamos los países que no tienen puntuacion
df <- df %>% arrange(desc(Score_2019)) %>%
filter(!Score_2019 == 'N/A')
#añadimos el siguiente comentario
df <- df %>%
mutate(Grado_libertad = case_when(
Score_2019 > 80 ~ "Libre",
Score_2019 > 70 & Score_2019 < 80 ~ "Generalmente libre",
Score_2019 > 60 & Score_2019 < 70 ~ "Moderadamente libre" ,
Score_2019 > 50 & Score_2019 < 60 ~ "Generalmente autoritario",
Score_2019 < 50 ~ "Autoritario"))
df <- df %>%
select(Country, Region, World.Rank, Region.Rank, Score_2019, Grado_libertad, Property.Rights, Judical.Effectiveness, Government.Integrity, Business.Freedom, Labor.Freedom, Monetary.Freedom, Trade.Freedom, Financial.Freedom, GDP_capita)
En esta tabla se puede observar y buscar cualquier elemento del data frame:
DT::datatable(df)
Vamos a analizar los 20 países con mayor y menor puntuación puntuación en el índice.
En primer lugar, el top 20 son países desarrollados, con unas instituciones democrátricas consolidadas que favorecen el crecimiento económico. En segundo lugar, el top 20 con menor puntuación son países cuyas instituciones son realmente poco beneficiosas para el crecimiento. La gran mayoría son países totalitarios que presentan una elevada corrupción.
# top 20
df_20 <- df %>%
group_by(Country) %>%
ungroup() %>%
slice_max(Score_2019, n = 20)
#Convertirmos a factor la columna Razón
df_20$Country <- factor(df_20$Country,levels = df_20$Country)
p1 <- ggplot(df_20, aes(y = fct_rev(Country),
x = Score_2019)) +
geom_col(fill = "#2A759F") +
geom_text(aes(label = Score_2019), hjust = -0.15,size = 3.25) +
scale_x_continuous(breaks = seq(0, 100, 30), limits = c(0, 100)) +
labs(title = "Índice de libertad económica",
subtitle = "Top 20, año 2019",
y = "Puntuación", x = "País") +
theme_classic()
p1
df_1 <- df %>%
select(Country, Score_2019)
df_1$Country <- recode(df_1$Country,
"United States"="USA",
"Hong Kong" = "HK",
"United Kingdom" = "UK",
"United Arab Emirates" = "EAU")
wordcloud2(data = df_1, shape = "circle", size = 0.3)
df_5 <- df %>%
group_by(Country) %>%
ungroup() %>%
slice_max(Score_2019, n = 5)
p2 <- treemap(df_5,
index = "Country",
vSize ="Score_2019",
type = "index",
palette = "Set2",
(col2rgb(bg.labels = c("white"), silent = TRUE)),
align.labels= list(c("center", "center"),
c("right", "bottom")),
title = "Top 5 con mayor índice de libertad económica")
p2
#> $tm
#> Country vSize vColor stdErr vColorValue level x0 y0
#> 1 Australia 80.9 1 80.9 NA 1 0.4208060 0.0000000
#> 2 Hong Kong 90.2 1 90.2 NA 1 0.0000000 0.4977728
#> 3 New Zealand 84.4 1 84.4 NA 1 0.4208060 0.3272654
#> 4 Singapore 89.4 1 89.4 NA 1 0.0000000 0.0000000
#> 5 Switzerland 81.9 1 81.9 NA 1 0.7147565 0.3272654
#> w h color
#> 1 0.5791940 0.3272654 #66C2A5
#> 2 0.4208060 0.5022272 #FC8D62
#> 3 0.2939505 0.6727346 #8DA0CB
#> 4 0.4208060 0.4977728 #E78AC3
#> 5 0.2852435 0.6727346 #A6D854
#>
#> $type
#> [1] "index"
#>
#> $vSize
#> [1] "Score_2019"
#>
#> $vColor
#> [1] NA
#>
#> $stdErr
#> [1] "Score_2019"
#>
#> $algorithm
#> [1] "pivotSize"
#>
#> $vpCoorX
#> [1] 0.02812148 0.97187852
#>
#> $vpCoorY
#> [1] 0.02239057 0.89798858
#>
#> $aspRatio
#> [1] 1.716375
#>
#> $range
#> [1] NA
#>
#> $mapping
#> [1] NA NA NA
#>
#> $draw
#> [1] TRUE
df_20 <- df %>%
slice_max(Score_2019, n = 20) %>%
select(Country, Region, World.Rank, Region.Rank, Score_2019, Grado_libertad) %>%
rename("País" = Country, "Región" = Region, "Ranking" = World.Rank, "Ranking regional" = Region.Rank, "Puntuación" = Score_2019, "Grado de libertad" = Grado_libertad)
gt_20 <- gt(df_20) %>%
tab_header(title = md("**Top 20 países con mayor libertad económica**"),
subtitle = "en 2019")
gt_20
Top 20 países con mayor libertad económica | |||||
---|---|---|---|---|---|
en 2019 | |||||
País | Región | Ranking | Ranking regional | Puntuación | Grado de libertad |
Hong Kong | Asia-Pacific | 1 | 1 | 90.2 | Libre |
Singapore | Asia-Pacific | 2 | 2 | 89.4 | Libre |
New Zealand | Asia-Pacific | 3 | 3 | 84.4 | Libre |
Switzerland | Europe | 4 | 1 | 81.9 | Libre |
Australia | Asia-Pacific | 5 | 4 | 80.9 | Libre |
Ireland | Europe | 6 | 2 | 80.5 | Libre |
United Kingdom | Europe | 7 | 3 | 78.9 | Generalmente libre |
Canada | Americas | 8 | 1 | 77.7 | Generalmente libre |
United Arab Emirates | Middle East and North Africa | 9 | 1 | 77.6 | Generalmente libre |
Taiwan | Asia-Pacific | 10 | 5 | 77.3 | Generalmente libre |
Iceland | Europe | 11 | 4 | 77.1 | Generalmente libre |
Netherlands | Europe | 13 | 5 | 76.8 | Generalmente libre |
United States | Americas | 12 | 2 | 76.8 | Generalmente libre |
Denmark | Europe | 14 | 6 | 76.7 | Generalmente libre |
Estonia | Europe | 15 | 7 | 76.6 | Generalmente libre |
Georgia | Europe | 16 | 8 | 75.9 | Generalmente libre |
Luxembourg | Europe | 17 | 9 | 75.9 | Generalmente libre |
Chile | Americas | 18 | 3 | 75.4 | Generalmente libre |
Sweden | Europe | 19 | 10 | 75.2 | Generalmente libre |
Finland | Europe | 20 | 11 | 74.9 | Generalmente libre |
# top 20
df_min <- df %>%
group_by(Country) %>%
ungroup() %>%
slice_min(Score_2019, n = 20)
#Convertirmos a factor la columna Razón
df_min$Country <- factor(df_min$Country,levels = df_min$Country)
p3 <- ggplot(df_min, aes(y = fct_rev(Country),
x = Score_2019)) +
geom_col(fill = "#2A759F") +
geom_text(aes(label = Score_2019), hjust = -0.15,size = 3.25) +
scale_x_continuous(breaks = seq(0, 100, 30), limits = c(0, 100)) +
labs(title = "Índice de libertad económica",
subtitle = "Top 20 con menor puntuación, año 2019",
y = "Puntuación", x = "País") +
theme_classic()
p3
df_min_5 <- df %>%
group_by(Country) %>%
ungroup() %>%
slice_min(Score_2019, n = 5)
p4 <- treemap(df_min_5,
index = "Country",
vSize ="Score_2019",
type = "index",
palette = "Set2",
(col2rgb(bg.labels = c("white"), silent = TRUE)),
align.labels= list(c("center", "center"),
c("right", "bottom")),
title = "Top 5 con menor índice de libertad económica")
p4
#> $tm
#> Country vSize vColor stdErr vColorValue level x0 y0
#> 1 Congo 39.7 1 39.7 NA 1 0.0000000 0.4949109
#> 2 Cuba 27.8 1 27.8 NA 1 0.5687410 0.5335570
#> 3 Eritrea 38.9 1 38.9 NA 1 0.0000000 0.0000000
#> 4 Korea, North 5.9 1 5.9 NA 1 0.9199865 0.0000000
#> 5 Venezuela 25.9 1 25.9 NA 1 0.5687410 0.0000000
#> w h color
#> 1 0.56874096 0.5050891 #66C2A5
#> 2 0.43125904 0.4664430 #FC8D62
#> 3 0.56874096 0.4949109 #8DA0CB
#> 4 0.08001347 0.5335570 #E78AC3
#> 5 0.35124557 0.5335570 #A6D854
#>
#> $type
#> [1] "index"
#>
#> $vSize
#> [1] "Score_2019"
#>
#> $vColor
#> [1] NA
#>
#> $stdErr
#> [1] "Score_2019"
#>
#> $algorithm
#> [1] "pivotSize"
#>
#> $vpCoorX
#> [1] 0.02812148 0.97187852
#>
#> $vpCoorY
#> [1] 0.02239057 0.89798858
#>
#> $aspRatio
#> [1] 1.716375
#>
#> $range
#> [1] NA
#>
#> $mapping
#> [1] NA NA NA
#>
#> $draw
#> [1] TRUE
df_min <- df %>%
slice_min(Score_2019, n = 20) %>%
select(Country, Region, World.Rank, Region.Rank, Score_2019, Grado_libertad) %>%
rename("País" = Country, "Región" = Region, "Ranking" = World.Rank, "Ranking regional" = Region.Rank, "Puntuación" = Score_2019, "Grado de libertad" = Grado_libertad)
gt_min <- gt(df_min) %>%
tab_header(title = md("**Top 20 países con menor libertad económica**"),
subtitle = "en 2019")
gt_min
Top 20 países con menor libertad económica | |||||
---|---|---|---|---|---|
en 2019 | |||||
País | Región | Ranking | Ranking regional | Puntuación | Grado de libertad |
Korea, North | Asia-Pacific | 180 | 43 | 5.9 | Autoritario |
Venezuela | Americas | 179 | 32 | 25.9 | Autoritario |
Cuba | Americas | 178 | 31 | 27.8 | Autoritario |
Eritrea | Sub-Saharan Africa | 177 | 47 | 38.9 | Autoritario |
Congo | Sub-Saharan Africa | 176 | 46 | 39.7 | Autoritario |
Zimbabwe | Sub-Saharan Africa | 175 | 45 | 40.4 | Autoritario |
Eq. Guinea | Sub-Saharan Africa | 174 | 44 | 41.0 | Autoritario |
Bolivia | Americas | 173 | 30 | 42.3 | Autoritario |
Timor-Leste | Asia-Pacific | 172 | 42 | 44.2 | Autoritario |
Algeria | Middle East and North Africa | 171 | 14 | 46.2 | Autoritario |
Ecuador | Americas | 170 | 29 | 46.9 | Autoritario |
Djibouti | Sub-Saharan Africa | 169 | 43 | 47.1 | Autoritario |
Kiribati | Asia-Pacific | 168 | 41 | 47.3 | Autoritario |
Sierra Leone | Sub-Saharan Africa | 167 | 42 | 47.5 | Autoritario |
Sudan | Sub-Saharan Africa | 166 | 41 | 47.7 | Autoritario |
Suriname | Americas | 165 | 28 | 48.1 | Autoritario |
Turkmenistan | Asia-Pacific | 164 | 40 | 48.4 | Autoritario |
Mozambique | Sub-Saharan Africa | 163 | 40 | 48.6 | Autoritario |
Burundi | Sub-Saharan Africa | 162 | 39 | 48.9 | Autoritario |
Central African Rep. | Sub-Saharan Africa | 161 | 38 | 49.1 | Autoritario |
Vamos a llevar a cabo un análisis de algunos de los componentes que considero que son importantes a la hora de explicar el grado de libertad de los países.
df_comp <- df %>%
select(!GDP_capita)
df_prop <- df_comp %>%
select(Country, Region, World.Rank, Region.Rank, Property.Rights)
df_prop1 <- df_prop %>%
slice_max(Property.Rights, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Property.Rights)
df_prop2 <- df_prop %>%
slice_min(Property.Rights, n = 5) %>%
arrange(desc(Property.Rights)) %>%
select(Country, Region, World.Rank, Region.Rank, Property.Rights)
#Convertirmos a factor la columna Razón
df_prop1$Country <- factor(df_prop1$Country,levels = df_prop1$Country)
ggplot(df_prop1, aes(y = fct_rev(Country),
x = Property.Rights)) +
geom_col(fill = "#2A759F", position = position_stack(reverse = TRUE)) +
geom_text(aes(label = Property.Rights), hjust = -0.15, size = 3.25) +
scale_x_continuous(breaks = seq(0, 100, 30), limits = c(0, 100)) +
labs(title = "Top 10 paises con mejores derechos de propiedad",
subtitle = "en 2019",
x = "Puntuación derechos de propiedad",
y = "Países") +
theme(axis.text.x = element_text(angle = 30)) +
theme_classic()
df_prop1 <- df_prop %>%
slice_max(Property.Rights, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Property.Rights) %>%
rename("País" = Country, "Región" = Region, "Ranking mundial" = World.Rank, "Ranking regional" = Region.Rank, "Derechos de propiedad" = Property.Rights)
knitr::kable(df_prop1,
align = "c",
caption = "Top 10 paises con mejores derechos de propiedad",
digits = 2) %>%
kableExtra::kable_styling(fixed_thead = list(enabled = T,
background = "white")) %>%
column_spec(1, background = "white")
País | Región | Ranking mundial | Ranking regional | Derechos de propiedad |
---|---|---|---|---|
Singapore | Asia-Pacific | 2 | 2 | 97.4 |
New Zealand | Asia-Pacific | 3 | 3 | 95.0 |
Hong Kong | Asia-Pacific | 1 | 1 | 93.3 |
United Kingdom | Europe | 7 | 3 | 92.3 |
Finland | Europe | 20 | 11 | 89.6 |
Sweden | Europe | 19 | 10 | 89.5 |
Netherlands | Europe | 13 | 5 | 88.0 |
Iceland | Europe | 11 | 4 | 87.4 |
Canada | Americas | 8 | 1 | 87.0 |
Denmark | Europe | 14 | 6 | 86.2 |
df_jud <- df_comp %>%
select(Country, Region, World.Rank, Region.Rank, Judical.Effectiveness)
df_jud1 <- df_jud %>%
slice_max(Judical.Effectiveness, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Judical.Effectiveness)
#Convertirmos a factor la columna Razón
df_jud1$Country<-factor(df_jud1$Country, levels = df_jud1$Country)
my_10 <- c('#9e0142','#d53e4f','#f46d43','#fdae61','#fee08b','#e6f598','#abdda4','#66c2a5','#3288bd','#5e4fa2')
ggplot(df_jud1, aes(y = fct_rev(Country), x = Judical.Effectiveness)) +
geom_col(fill = my_10) +
geom_text(aes(label = Judical.Effectiveness), hjust = -0.15, size = 3.25) +
scale_fill_manual(values = my_10) +
scale_x_continuous(breaks = seq(0, 100, 30), limits = c(0, 100)) +
labs(title = "Top 10 paises con mejor efectividad judicial",
subtitle = "en 2019",
x = "Puntuación en efectividad judicial",
y = "Países") +
theme_classic() +
theme(axis.text.x = element_text(angle =30))
df_jud1 <- df_jud %>%
slice_max(Judical.Effectiveness, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Judical.Effectiveness) %>%
rename("País" = Country, "Región" = Region, "Ranking mundial" = World.Rank, "Ranking regional" = Region.Rank, "Efectividad judicial" = Judical.Effectiveness)
knitr::kable(df_jud1,
align = "c",
caption = "Top 10 paises con mayor efectividad judicial",
digits = 2) %>%
kableExtra::kable_styling(fixed_thead = list(enabled = T,
background = "white")) %>%
column_spec(1, background = "white")
País | Región | Ranking mundial | Ranking regional | Efectividad judicial |
---|---|---|---|---|
Singapore | Asia-Pacific | 2 | 2 | 92.4 |
United Arab Emirates | Middle East and North Africa | 9 | 1 | 87.1 |
Australia | Asia-Pacific | 5 | 4 | 86.5 |
United Kingdom | Europe | 7 | 3 | 85.9 |
Sweden | Europe | 19 | 10 | 84.0 |
New Zealand | Asia-Pacific | 3 | 3 | 83.5 |
Rwanda | Sub-Saharan Africa | 32 | 2 | 83.2 |
Switzerland | Europe | 4 | 1 | 82.0 |
Finland | Europe | 20 | 11 | 81.2 |
Norway | Europe | 26 | 15 | 81.2 |
Entran en juego paises africanos como Namibia o Nigeria. También Estados Unidos, de los pocos países occidentales en mantener su tradicional flexibilidad laboral, asunto muy criticado por los países europeos, que han impuesto una mayor rigidez (salarios mínimos, mayores indemnizaciones por despido, etc) desde los años 70 y que explicaron el período de histéresis cuyos efectos incluso aún perduran. Es por ello que solo vemos a un país europeo en el top 10.
df_lab <- df_comp %>%
select(Country, Region, World.Rank, Region.Rank, Labor.Freedom)
df_lab1 <- df_lab %>%
slice_max(Labor.Freedom, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Labor.Freedom)
#Convertirmos a factor la columna Razón
df_lab1$Country<-factor(df_lab1$Country, levels = df_lab1$Country)
ggplot(df_lab1, aes(y = fct_rev(Country), x = Labor.Freedom)) +
geom_col(fill = "#2A759F") +
geom_text(aes(label = Labor.Freedom), hjust = -0.15, size = 3.25) +
scale_x_continuous(breaks = seq(0, 100, 20), limits = c(0, 100)) +
labs(title = "Top 10 paises con mayor libertad laboral",
subtitle = "en 2019",
x = "Puntuación en libertad laboral",
y = "Países") +
theme_classic() +
theme(axis.text.x = element_text(angle =30))
df_lab1 <- df_lab %>%
slice_max(Labor.Freedom, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Labor.Freedom) %>%
rename("País" = Country, "Región" = Region, "Ranking mundial" = World.Rank, "Ranking regional" = Region.Rank, "Libertad laboral" = Labor.Freedom)
knitr::kable(df_lab1,
align = "c",
caption = "Top 10 paises con mayor libertad laboral",
digits = 2) %>%
kableExtra::kable_styling(fixed_thead = list(enabled = T,
background = "white")) %>%
column_spec(1, background = "white")
País | Región | Ranking mundial | Ranking regional | Libertad laboral |
---|---|---|---|---|
Singapore | Asia-Pacific | 2 | 2 | 91.0 |
Brunei | Asia-Pacific | 63 | 14 | 90.8 |
United States | Americas | 12 | 2 | 89.4 |
Hong Kong | Asia-Pacific | 1 | 1 | 89.2 |
New Zealand | Asia-Pacific | 3 | 3 | 86.7 |
Denmark | Europe | 14 | 6 | 86.4 |
Kazakhstan | Asia-Pacific | 59 | 12 | 86.2 |
Namibia | Sub-Saharan Africa | 99 | 10 | 85.1 |
Australia | Asia-Pacific | 5 | 4 | 84.1 |
Nigeria | Sub-Saharan Africa | 111 | 14 | 83.3 |
Según la economía keynesiana, una mayor libertad financiera, y por tanto, una menor desregularización puede llevar consigo la mayor probabilidad de crisis financieras. Con la era liberal de los años 80, comenzó un proceso liberalizador de las finanzas, cuyo foco principal fue Estados Unidos y Reino Unido. Muchos economistas afirman que este proceso conllevo a la crisis financiera de 2007. Este hecho hizo que a posteriori la regularización se implementara en mayor medida.
df_fin <- df_comp %>%
select(Country, Region, World.Rank, Region.Rank, Financial.Freedom)
df_fin1 <- df_fin %>%
slice_max(Financial.Freedom, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Financial.Freedom)
#Convertirmos a factor la columna Razón
df_fin1$Country<-factor(df_fin1$Country, levels = df_fin1$Country)
ggplot(df_fin1, aes(y = fct_rev(Country), x = Financial.Freedom)) +
geom_col(fill = "#2A759F") +
geom_text(aes(label = Financial.Freedom), hjust = -0.15, size = 3.25) +
scale_x_continuous(breaks = seq(0, 100, 20), limits = c(0, 100)) +
labs(title = "Top 10 paises con mayor libertad financiera",
subtitle = "en 2019",
x = "Puntuación en libertad financiera",
y = "Países") +
theme(axis.text.x = element_text(angle =30)) +
theme_classic()
df_fin1 <- df_fin %>%
slice_max(Financial.Freedom, n = 10) %>%
select(Country, Region, World.Rank, Region.Rank, Financial.Freedom) %>%
rename("País" = Country, "Región" = Region, "Ranking mundial" = World.Rank, "Ranking regional" = Region.Rank, "Libertad financiera" = Financial.Freedom)
knitr::kable(df_fin1,
align = "c",
caption = "Top 10 paises con mayor libertad financiera",
digits = 2) %>%
kableExtra::kable_styling(fixed_thead = list(enabled = T,
background = "white")) %>%
column_spec(1, background = "white")
País | Región | Ranking mundial | Ranking regional | Libertad financiera |
---|---|---|---|---|
Hong Kong | Asia-Pacific | 1 | 1 | 90 |
Switzerland | Europe | 4 | 1 | 90 |
Australia | Asia-Pacific | 5 | 4 | 90 |
Singapore | Asia-Pacific | 2 | 2 | 80 |
New Zealand | Asia-Pacific | 3 | 3 | 80 |
United Kingdom | Europe | 7 | 3 | 80 |
Canada | Americas | 8 | 1 | 80 |
Netherlands | Europe | 13 | 5 | 80 |
United States | Americas | 12 | 2 | 80 |
Denmark | Europe | 14 | 6 | 80 |
Luxembourg | Europe | 17 | 9 | 80 |
Sweden | Europe | 19 | 10 | 80 |
Finland | Europe | 20 | 11 | 80 |
Czech Rep. | Europe | 23 | 13 | 80 |
Bahrain | Middle East and North Africa | 54 | 5 | 80 |
Vemos que la región con mayor libertad económica, y por tanto, con mayor media en este índice es Europa.
La Fundación Heritage informa que el 20% superior en el índice tiene el doble del ingreso per cápita que aquellos en el segundo quintil, y cinco veces el del 20% inferior.
# Cogemos el top 5 de cada región
df_max <- df %>%
group_by(Region) %>%
slice_max(Score_2019, n = 5) %>%
select(Country, Region, Region.Rank, Score_2019, Grado_libertad)
df_max$Country<-factor(df_max$Country, levels = df_max$Country)
my_colors <- c('#e41a1c','#377eb8','#4daf4a','#984ea3','#ff7f00')
h <- ggplot(df_max, aes(y = fct_rev(Country),
x = Score_2019,
fill = Region)) +
geom_col() +
scale_fill_manual(values = my_colors) +
scale_x_continuous(breaks = seq(0, 100, 20), limits = c(0, 100)) +
labs(title = "Índice de libertad económica por regiones",
subtitle = "Top 5 por region",
y = "País",
x = "Puntuación en 2019") +
theme_classic()
h
df_max <- df %>%
group_by(Region) %>%
slice_max(Score_2019, n = 5) %>%
select(Country, Region, Region.Rank, Score_2019, Grado_libertad) %>%
rename("País" = Country, "Región" = Region, "Ranking regional" = Region.Rank, "Puntuación" = Score_2019, "Grado de libertad" = Grado_libertad)
gt_max<- gt(df_max) %>%
tab_header(title = md("**Top 5 por regiones**"),
subtitle = "en 2019")
gt_max
Top 5 por regiones | |||
---|---|---|---|
en 2019 | |||
País | Ranking regional | Puntuación | Grado de libertad |
Americas | |||
Canada | 1 | 77.7 | Generalmente libre |
United States | 2 | 76.8 | Generalmente libre |
Chile | 3 | 75.4 | Generalmente libre |
Saint Lucia | 4 | 68.7 | Moderadamente libre |
Jamaica | 5 | 68.6 | Moderadamente libre |
Uruguay | 6 | 68.6 | Moderadamente libre |
Asia-Pacific | |||
Hong Kong | 1 | 90.2 | Libre |
Singapore | 2 | 89.4 | Libre |
New Zealand | 3 | 84.4 | Libre |
Australia | 4 | 80.9 | Libre |
Taiwan | 5 | 77.3 | Generalmente libre |
Europe | |||
Switzerland | 1 | 81.9 | Libre |
Ireland | 2 | 80.5 | Libre |
United Kingdom | 3 | 78.9 | Generalmente libre |
Iceland | 4 | 77.1 | Generalmente libre |
Netherlands | 5 | 76.8 | Generalmente libre |
Middle East and North Africa | |||
United Arab Emirates | 1 | 77.6 | Generalmente libre |
Israel | 2 | 72.8 | Generalmente libre |
Qatar | 3 | 72.6 | Generalmente libre |
Jordan | 4 | 66.5 | Moderadamente libre |
Bahrain | 5 | 66.4 | Moderadamente libre |
Sub-Saharan Africa | |||
Mauritius | 1 | 73.0 | Generalmente libre |
Rwanda | 2 | 71.1 | Generalmente libre |
Botswana | 3 | 69.5 | Moderadamente libre |
Cape Verde | 4 | 63.1 | Moderadamente libre |
Côte d'Ivoire | 5 | 62.4 | Moderadamente libre |
my_palette <- c('#1b9e77','#d95f02','#7570b3','#e7298a','#66a61e')
df_regiones <- df %>%
group_by(Region) %>%
select(Country, Region, Region.Rank, Score_2019, Grado_libertad)
p5 <- ggplot(df_regiones, aes(x = Region,
y = Score_2019,
fill = Region)) +
geom_boxplot() +
geom_jitter(width = 0.15, alpha = 0.2, color = "tomato") +
scale_fill_manual(values = my_palette) +
scale_y_continuous(breaks = seq(0, 100, 20), limits = c(0, 100)) +
coord_flip() +
labs(title = "Puntuación por regiones",
subtitle = "en 2019",
x = "Región",
y = "Puntuación") +
theme_classic() +
theme(legend.position = "none",
panel.background = element_rect(fill = NA))
p5
world <- ne_countries(scale = "medium", returnclass = "sf")
world <- world %>% filter(subregion != "Antarctica") %>% filter(admin != "Greenland")
world <- world %>% select(name, iso_a3, geometry)
df_join <- left_join (df, world, by = c("Country" = "name"))
df_world <- df_join %>%
mutate(Score_2019_5 = ntile(Score_2019, 5)) %>%
select(Country, Region, World.Rank, Region.Rank, Score_2019, Score_2019_5, geometry)
gg <- ggplot(df_world, aes(fill = Score_2019, geometry = geometry)) +
geom_sf() +
scale_fill_gradient("Puntuación", high = "#993404", low = "#ffffd4", breaks = seq(20,100, 20), limits = c(20,100)) +
labs(title = "Índice de libertad económica",
subtitle = "en 2019",
caption = "Los paises en blanco no tienen datos") +
theme(panel.background = element_rect(fill = NA),
legend.text = element_text(face = "italic"),
legend.title = element_text(face = "italic"),
legend.position = "bottom",
legend.direction = "horizontal",
axis.ticks = element_line(linetype = "blank"),
axis.text = element_text(colour = "white"))
gg
df_reg <- df %>%
group_by(Region) %>%
summarise(Media = mean(Score_2019)) %>%
arrange(desc(Media)) %>%
select(Region, Media)
gt_reg <- gt(df_reg) %>%
tab_header(title = md("**Puntuación media regional en el índice de libertad económica**"),
subtitle = "en 2019")
gt_reg
Puntuación media regional en el índice de libertad económica | |
---|---|
en 2019 | |
Region | Media |
Europe | 68.62727 |
Middle East and North Africa | 61.25714 |
Asia-Pacific | 60.63488 |
Americas | 59.60000 |
Sub-Saharan Africa | 54.18298 |
La Fundación Heritage informa que el 20% superior en el índice tiene el doble del ingreso per cápita que aquellos en el segundo quintil, y cinco veces el del 20% inferior, por lo tanto hay una correlación positiva entre libertad económica y desarrollo. Queremos comprobar esto.
Se puede observar que los países con mayor libertad económica tienen un mayor PIB per cápita en términos medios, excepto para el caso de la región de Oriente Medio y Norte de África, que poseen más PIB per cápita que los países europeos, por el negocio del petróleo.
df <- df
f <- ggplot(df, aes(GDP_capita,
Score_2019,
alpha = 0.5)) +
geom_point(aes(color = Country)) +
geom_smooth(formula = y ~ x, method = "lm") +
labs(title = "Relación PIB per cápita y libertad económica",
subtitle = "en 2019",
x = "PIB per cápita",
y = "Libertad económica") +
theme_classic() +
theme(legend.position = "none",
panel.background = element_rect(fill = NA))
f
#con ggplotly no sale el gráfico
df_gdp <- df %>%
group_by(Region) %>%
summarise(media_GDP_capita = mean(GDP_capita)) %>%
arrange(desc(media_GDP_capita))
df_gdp$Region <- factor(df_gdp$Region, levels = df_gdp$Region)
my_colors <- c('#e41a1c','#377eb8','#4daf4a','#984ea3','#ff7f00')
g <- ggplot(df_gdp, aes(y = fct_rev(Region),
x = media_GDP_capita,
fill = Region)) +
geom_col(show.legend = FALSE) +
scale_fill_manual(values = my_colors) +
scale_x_continuous(breaks = seq(0, 45000, 5000), limits = c(0, 45000)) +
geom_text(aes(label = round(media_GDP_capita, digits = 0)), hjust = -0.10, size = 3.25) +
labs(title = "PIB per cápita medio por regiones",
subtitle = "en 2019",
y = "Región",
x = "PIB per cápita medio") +
theme(panel.background = element_rect(fill = NA)) +
theme_classic()
g
df_puntuacion <- df %>%
group_by(Region) %>%
summarise(media_score_2019 = mean(Score_2019)) %>%
arrange(desc(media_score_2019))
df_puntuacion$Region <- factor(df_puntuacion$Region ,levels = df_puntuacion$Region)
ggplot(df_puntuacion, aes(x = media_score_2019,
y = fct_rev(Region),
fill = Region)) +
geom_col(show.legend = FALSE) +
geom_text(aes(label = round(media_score_2019, digits = 2)), hjust = -0.10, size = 3.25) +
scale_fill_manual(values = my_colors) +
coord_cartesian(xlim = c(40, 70)) +
labs(title = "Puntuación media por regiones",
subtitle = "en 2019",
y = "Región",
x = "Puntuación media") +
theme_classic() +
theme(panel.background = element_rect(fill = NA))
df_join <- left_join(df_puntuacion, df_gdp, by = "Region") %>%
arrange(desc(media_score_2019))
df_gdp <- df %>%
group_by(Region) %>%
summarise(media_GDP_capita = mean(GDP_capita))
df_puntuacion <- df %>%
group_by(Region) %>%
summarise(media_score_2019 = mean(Score_2019))
df_join <- left_join(df_puntuacion, df_gdp, by = "Region") %>%
arrange(desc(media_score_2019)) %>%
rename("Región" = Region,
"Puntuación media" = media_score_2019,
"PIB per cápita medio" = media_GDP_capita)
knitr::kable(df_join,
align = "c",
caption = "Puntuación y PIB per cápita medios por regiones",
digits = 2) %>%
kableExtra::kable_styling(fixed_thead = list(enabled = T,
background = "white")) %>%
column_spec(1, background = "white")
Región | Puntuación media | PIB per cápita medio |
---|---|---|
Europe | 68.63 | 34783.84 |
Middle East and North Africa | 61.26 | 38826.79 |
Asia-Pacific | 60.63 | 20202.26 |
Americas | 59.60 | 16897.56 |
Sub-Saharan Africa | 54.18 | 5698.36 |
The Heritage Foundation (2019): World Economic Freedom Index
- Session info ---------------------------------------------------------------
setting value
version R version 4.1.1 (2021-08-10)
os Windows 10 x64
system x86_64, mingw32
ui RTerm
language (EN)
collate Spanish_Spain.1252
ctype Spanish_Spain.1252
tz Europe/Paris
date 2022-01-09
- Packages -------------------------------------------------------------------
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.1)
backports 1.2.1 2020-12-09 [1] CRAN (R 4.1.1)
broom 0.7.9 2021-07-27 [1] CRAN (R 4.1.1)
bslib 0.3.0 2021-09-02 [1] CRAN (R 4.1.1)
cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.1.1)
checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.1.1)
class 7.3-19 2021-05-03 [2] CRAN (R 4.1.1)
classInt 0.4-3 2020-04-07 [1] CRAN (R 4.1.1)
cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.1)
clipr 0.7.1 2020-10-08 [1] CRAN (R 4.1.1)
colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.1)
commonmark 1.7 2018-12-01 [1] CRAN (R 4.1.1)
crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.1)
crosstalk 1.1.1 2021-01-12 [1] CRAN (R 4.1.1)
curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.1)
data.table 1.14.0 2021-02-21 [1] CRAN (R 4.1.1)
DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.1)
dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.1.1)
desc 1.3.0 2021-03-05 [1] CRAN (R 4.1.1)
details 0.2.1 2020-01-12 [1] CRAN (R 4.1.1)
digest 0.6.27 2020-10-24 [1] CRAN (R 4.1.1)
dplyr * 1.0.7 2021-06-18 [1] CRAN (R 4.1.1)
DT 0.19 2021-09-02 [1] CRAN (R 4.1.1)
e1071 1.7-8 2021-07-28 [1] CRAN (R 4.1.1)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.1)
evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.1)
fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.1)
farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.1)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.1)
forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.1.1)
foreign 0.8-81 2020-12-22 [2] CRAN (R 4.1.1)
formatR 1.11 2021-06-01 [1] CRAN (R 4.1.1)
fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.1)
generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.1)
gganimate * 1.0.7 2020-10-15 [1] CRAN (R 4.1.1)
ggfittext 0.9.1 2021-01-30 [1] CRAN (R 4.1.2)
ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.1)
ggThemeAssist * 0.1.5 2016-08-13 [1] CRAN (R 4.1.1)
gifski 1.4.3-1 2021-05-02 [1] CRAN (R 4.1.1)
glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.1)
gridBase 0.4-7 2014-02-24 [1] CRAN (R 4.1.1)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.1.1)
gt * 0.3.1 2021-08-07 [1] CRAN (R 4.1.1)
gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.1)
haven 2.4.3 2021-08-04 [1] CRAN (R 4.1.1)
here 1.0.1 2020-12-13 [1] CRAN (R 4.1.1)
highr 0.9 2021-04-16 [1] CRAN (R 4.1.1)
hms 1.1.0 2021-05-17 [1] CRAN (R 4.1.1)
htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.1)
httpuv 1.6.3 2021-09-09 [1] CRAN (R 4.1.1)
httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.1)
igraph 1.2.7 2021-10-15 [1] CRAN (R 4.1.1)
jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.1.1)
jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.1)
kableExtra * 1.3.4 2021-02-20 [1] CRAN (R 4.1.1)
KernSmooth 2.23-20 2021-05-03 [2] CRAN (R 4.1.1)
klippy * 0.0.0.9500 2021-11-17 [1] Github (rlesur/klippy@378c247)
knitr * 1.34 2021-09-09 [1] CRAN (R 4.1.1)
labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.1)
later 1.3.0 2021-08-18 [1] CRAN (R 4.1.1)
lattice 0.20-44 2021-05-02 [2] CRAN (R 4.1.1)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.1.1)
lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1)
lubridate 1.7.10 2021-02-26 [1] CRAN (R 4.1.1)
magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.1)
Matrix 1.3-4 2021-06-01 [2] CRAN (R 4.1.1)
mgcv 1.8-36 2021-06-01 [2] CRAN (R 4.1.1)
mime 0.11 2021-06-23 [1] CRAN (R 4.1.1)
miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.1.1)
modelr 0.1.8 2020-05-19 [1] CRAN (R 4.1.1)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.1)
nlme 3.1-152 2021-02-04 [2] CRAN (R 4.1.1)
openxlsx 4.2.4 2021-06-16 [1] CRAN (R 4.1.1)
pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.1)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.1)
plotly * 4.9.4.1 2021-06-18 [1] CRAN (R 4.1.1)
png 0.1-7 2013-12-03 [1] CRAN (R 4.1.1)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.1)
progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.1)
promises 1.2.0.1 2021-02-11 [1] CRAN (R 4.1.1)
proxy 0.4-26 2021-06-07 [1] CRAN (R 4.1.1)
purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.1.1)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.1.1)
Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.1)
readr * 2.0.1 2021-08-10 [1] CRAN (R 4.1.1)
readxl 1.3.1 2019-03-13 [1] CRAN (R 4.1.1)
reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1)
rgeos 0.5-8 2021-09-22 [1] CRAN (R 4.1.1)
rio * 0.5.27 2021-06-21 [1] CRAN (R 4.1.1)
rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.1)
rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1)
rnaturalearth * 0.1.0 2017-03-21 [1] CRAN (R 4.1.1)
rnaturalearthdata 0.1.0 2017-02-21 [1] CRAN (R 4.1.1)
rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.1)
rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.1)
rvest 1.0.1 2021-07-26 [1] CRAN (R 4.1.1)
sass 0.4.0 2021-05-12 [1] CRAN (R 4.1.1)
scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.1)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.1)
sf * 1.0-2 2021-07-26 [1] CRAN (R 4.1.1)
shiny 1.7.0 2021-09-22 [1] CRAN (R 4.1.1)
sp 1.4-5 2021-01-10 [1] CRAN (R 4.1.1)
stringi 1.7.5 2021-10-04 [1] CRAN (R 4.1.1)
stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.1)
svglite 2.0.0 2021-02-20 [1] CRAN (R 4.1.1)
systemfonts 1.0.3 2021-10-13 [1] CRAN (R 4.1.1)
tibble * 3.1.4 2021-08-25 [1] CRAN (R 4.1.1)
tidyr * 1.1.3 2021-03-03 [1] CRAN (R 4.1.1)
tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.1)
tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.1.1)
treemap * 2.4-3 2021-08-22 [1] CRAN (R 4.1.1)
treemapify * 2.5.5 2021-01-08 [1] CRAN (R 4.1.2)
tweenr 1.0.2 2021-03-23 [1] CRAN (R 4.1.1)
tzdb 0.1.2 2021-07-20 [1] CRAN (R 4.1.1)
units 0.7-2 2021-06-08 [1] CRAN (R 4.1.1)
utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.1)
vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.1)
viridis * 0.6.2 2021-10-13 [1] CRAN (R 4.1.1)
viridisLite * 0.4.0 2021-04-13 [1] CRAN (R 4.1.1)
webshot 0.5.2 2019-11-22 [1] CRAN (R 4.1.1)
withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.1)
wordcloud2 * 0.2.1 2018-01-03 [1] CRAN (R 4.1.2)
xfun 0.25 2021-08-06 [1] CRAN (R 4.1.1)
xml2 1.3.2 2020-04-23 [1] CRAN (R 4.1.1)
xtable 1.8-4 2019-04-21 [1] CRAN (R 4.1.1)
yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.1)
zip 2.2.0 2021-05-31 [1] CRAN (R 4.1.1)
[1] C:/Users/MAYTE/Documents/R/win-library/4.1
[2] C:/Program Files/R/R-4.1.1/library