-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSC_freedom.R
135 lines (120 loc) · 3.69 KB
/
SC_freedom.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
library(tidyverse)
library(camcorder)
library(showtext)
library(patchwork)
library(ggtext)
# Set plot size
gg_record(
dir = file.path(tempdir(),"recording"),
device = "png",
width = 10,
height = 10*1.618,
units = "cm",
dpi = 300
)
# Load fonts
font_add_google("Barlow Condensed","barlow")
font_add_google("Archivo Black","archivo")
font_add_google("Archivo Narrow","arch")
font_add_google("Kreon","kreon")
# Automatically use {showtext} for plots
showtext_auto()
# Colors
pal <- c(
'Americas'='#FFB30F',
'Europe'='#264653',
'Oceania'='#2A9D8F',
'Asia'="#A23E48",
'Africa'='#E76F51'
)
# Load data
freedom<-readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-02-22/freedom.csv')
# Prep data
reg<-freedom%>%
group_by(Region_Name,year)%>%
summarise(
CL = mean(na.omit(CL)),
PR = mean(na.omit(PR))
)
# Make plot
cap <- tibble(
x=2021.5,y=0.7,
label="**Data:** Freedom House **| Plot:** @BjnNowak"
)
# Civil liberties
cl <- ggplot(reg,aes(x=year,y=CL,color=Region_Name))+
geom_jitter(data=freedom,alpha=0.2,size=0.8)+
geom_line(size=1.5)+
annotate(
'text',label='civil liberties',x=1992,y=4,hjust=0.5,angle=90,
family='archivo',size=25,alpha=0.5)+
annotate(
'text',label='high',x=1995.5,y=1,hjust=0,angle=0,
family='arch',size=15,alpha=0.8,color='black')+
annotate(
'text',label='low',x=1995.5,y=7,hjust=0,angle=0,
family='arch',size=15,alpha=0.8,color='black')+
annotate(
'text',label='dots show the score per country and per year\nlines indicate the mean per continent',
x=2020,y=7,hjust=1,angle=0,lineheight=0.35,fontface='italic',
family='arch',size=7,alpha=0.8,color='black')+
geom_richtext(
data=cap,
aes(x=x, y=y, label = label),
col="grey20",
size=7,family="arch",angle=270,hjust=0,vjust=1,lineheight=0.40,
fill = NA, label.color = NA,
label.padding = grid::unit(rep(0, 4), "pt")
)+
scale_color_manual(values=pal)+
scale_y_reverse()+
scale_x_continuous(
limits=c(1990,2022)
)+
guides(color='none')+
theme_minimal()+
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = margin(0,0,0,0),
axis.title=element_blank(),
axis.text=element_blank(),
)
# Political rights
pr <- ggplot(reg,aes(x=year,y=PR,color=Region_Name))+
geom_jitter(data=freedom,alpha=0.2,size=0.8)+
geom_line(size=1.5)+
annotate(
'text',label='political rights',x=1992,y=4,hjust=0.5,angle=90,
family='archivo',size=25,alpha=0.5)+
annotate(
'text',label='Europe',x=2008,y=1.4,hjust=0.5,angle=0,
family='archivo',size=10,alpha=0.9,color='#264653')+
annotate(
'text',label='Oceania',x=2017,y=1.4,hjust=0.5,angle=0,
family='archivo',size=10,alpha=0.9,color='#2A9D8F')+
annotate(
'text',label='Americas',x=2002,y=2.6,hjust=0.5,angle=0,
family='archivo',size=10,alpha=0.9,color='#FFB30F')+
annotate(
'text',label='Africa',x=2016,y=4.3,hjust=0.5,angle=0,
family='archivo',size=10,alpha=0.9,color='#E76F51')+
annotate(
'text',label='Asia',x=2006,y=5.2,hjust=0.5,angle=0,
family='archivo',size=10,alpha=0.9,color='#A23E48')+
scale_y_reverse()+
scale_color_manual(values=pal)+
scale_x_continuous(
limits=c(1990,2022),breaks=c(2000,2010,2020)
)+
guides(color='none')+
theme_minimal()+
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = margin(0,0,8,0),
axis.title=element_blank(),
axis.text.y=element_blank(),
axis.text.x=element_text(family='arch',size=35)
)
cl/pr