map <- read.csv("~/Univalle/Visualizacion de datos/Choroplet Maps 1/globeMap.csv")

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.3
map1 = ggplot(map, aes(x=long, y=lat, group=as.factor(group)))
map1 = map1 + geom_polygon(aes(fill=Continent_Name, color=Continent_Name))
map1 = map1 + scale_fill_viridis_d()
map1 = map1 + labs(title = "Mapa Mundial por continentes", subtitle = "Paises demarcados", 
                   caption = "Dataset de ggplot map",x="Longitud", y= "Latitud")

map1

HDI Data

ihdi <- read.csv2("~/Univalle/Visualizacion de datos/Choroplet Maps 1/Coefficient_of_human_inequality.csv", na.strings="")

# Create subset year 2017
ihdi_2017 = subset(ihdi, ihdi$year == "X2017")

# Rename IHDI  dataset column to match with map column
colnames(ihdi_2017)[5] = "Three_Letter_Country_Code"

# Add Data to the map
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
mapData = left_join(map, ihdi_2017, by = c("Three_Letter_Country_Code"))

# Create ggplot object and save it in an object
map1 = ggplot(mapData, aes(x=long, y=lat, group=as.factor(group)))
map1 = map1 + geom_polygon(aes(fill=value))
map1 = map1 + scale_fill_viridis_c(option = "magma")

# Add labels
map1 = map1 + labs(title = "Indice de desarrollo de inequidad mundial para 2017", subtitle = "Indices de inequidad de salud, educacion e ingresos", caption = "En gris los territorios que no tienen indices. Fuente UN",x="Longitud", y= "Latitud")

# Add Margins
map1 = map1 + theme_bw()

map1