library(tidyverse)
library(patchwork)
library(RColorBrewer)
worldHappiness = read.csv('worldHappiness.csv')
head(worldHappiness)
## region long lat group order Ladder.score Social.support
## 1 Aruba -69.89912 12.45200 1 1 NA NA
## 2 Aruba -69.89571 12.42300 1 2 NA NA
## 3 Aruba -69.94219 12.43853 1 3 NA NA
## 4 Aruba -70.00415 12.50049 1 4 NA NA
## 5 Aruba -70.06612 12.54697 1 5 NA NA
## 6 Aruba -70.05088 12.59707 1 6 NA NA
## Healthy.life.expectancy Freedom.to.make.life.choices Generosity
## 1 NA NA NA
## 2 NA NA NA
## 3 NA NA NA
## 4 NA NA NA
## 5 NA NA NA
## 6 NA NA NA
## Perceptions.of.corruption Ladder.score.in.Dystopia
## 1 NA NA
## 2 NA NA
## 3 NA NA
## 4 NA NA
## 5 NA NA
## 6 NA NA
1. Reproduce a world map with countries colored by corruption
# Let's create a map with world_happiness
ggplot(data =worldHappiness %>% arrange(order),
aes(x=long,y=lat,
group=group,
fill=Perceptions.of.corruption))+
geom_polygon(color='black',alpha=.6,linewidth=.1)+
coord_cartesian(ylim=c(-55,90))+
theme_bw()+
scale_fill_gradientn("Perception of\nCorruption",colors = rev(brewer.pal(9,name="RdYlBu")),
na.value='black')+
labs(x="Longitude", y = "Latitude",
title = "Perceptions of Corruption by Country",
subtitle = "(Data provided by World happiness Report)",
caption = "Note: Antarctica has been removed, but rest assured\n that penguins are generally pretty happy.")

?geom_polygon
?scale_fill_gradientn
?brewer.pal
2. Make your own plot with new column data and colors
ggplot(data = worldHappiness %>%
arrange(order),
aes(x = long,
y = lat,
group = group,
fill = Freedom.to.make.life.choices)) + # Life choice freedom values
geom_polygon(color = 'black',
alpha = 0.7,
linewidth = 0.15) +
coord_cartesian(ylim = c(-55, 90)) +
theme_minimal() +
scale_fill_gradientn('Freedom to Make\nLife Choices',
colors = brewer.pal(9,
name = 'RdYlGn'), # Red, yellow, green value spectrum
na.value = 'white') + # Black --> white NA countries
labs(x = 'Longitude',
y = 'Latitude',
title = 'Freedom to Make Life Choices by Country',
subtitle = '(Data provided by World Happiness Report)')
