-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript_02A_Descriptive_LinePlot.R
90 lines (71 loc) · 3.73 KB
/
Script_02A_Descriptive_LinePlot.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
# Replication Code
# Better Incentives, Better Marks: A Synthetic Control Evaluation of the New Educational Policies in Ceará, Brazil
# Script 02A - Descriptive Statistics - Line Plots
# Bruno Ponne
library(ggplot2)
library(dplyr)
library(ggpubr)
load("data/DATA_COMPLETE.RData")
# Time Series Plots (Figure 01)
DATA_COMPLETE$group <- -1
DATA_COMPLETE$group[DATA_COMPLETE$abbr_state == "CE"] <- "CE"
DATA_COMPLETE$group[DATA_COMPLETE$abbr_state != "CE"] <- "Other States"
DATA_GRAPH <- DATA_COMPLETE %>%
group_by(year, group, subject, grade) %>%
summarise(score = mean(score))
DATA_GRAPH$grade[DATA_GRAPH$grade=="P"] <- "Primary Education"
DATA_GRAPH$grade[DATA_GRAPH$grade=="LS"] <- "Lower Secondary Education"
DATA_GRAPH$grade[DATA_GRAPH$grade=="US"] <- "Upper Secondary Education"
DATA_GRAPH$grade <- factor(DATA_GRAPH$grade, levels = c("Primary Education", "Lower Secondary Education", "Upper Secondary Education"))
DATA_GRAPH$subject[DATA_GRAPH$subject=="math"] <- "Mathematics"
DATA_GRAPH$subject[DATA_GRAPH$subject=="port"] <- "Portuguese"
# Figure 01a
fig_01a <- ggplot(data = filter(DATA_GRAPH, grade == "Primary Education" ), aes(x=year, y= score, color = group))+
geom_vline(xintercept = 2008, color = "#636363", linetype = "dashed", size = 0.9)+
geom_vline(xintercept = 2011, color = "#636363", linetype = "dashed", size = 0.9)+
geom_line(size = 0.9)+
scale_color_manual(values= c("#01665e","#d8b365"),
labels= c( "Ceará", "Average of Other States"),
name = "")+
ylab("Score")+
xlab("Year")+
scale_x_continuous(labels = c(1995,2000,2005,2010,2015,2020))+
annotate("text", x = 2006.5, y = 220, label = "TI", color = "#636363", size = 4)+
annotate("text", x = 2014.5, y = 142, label = "TI + TA", color = "#636363", size = 4)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text = element_text(colour = "#636363"),
axis.line = element_line(colour = "gray"),
panel.border = element_rect(colour = "gray"),
legend.position = "bottom",
panel.spacing = unit(1.1, "lines"),
strip.background = element_rect(fill="white", linetype = "blank"),
text = element_text(family="Helvetica", color ="#636363"))+
facet_grid(vars(grade), vars(subject))
# Figure 01b
fig_01b <- ggplot(data = filter(DATA_GRAPH, grade == "Lower Secondary Education" ), aes(x=year, y= score, color = group))+
geom_vline(xintercept = 2008, color = "#636363", linetype = "dashed", size = 0.9)+
geom_vline(xintercept = 2015, color = "#636363", linetype = "dashed", size = 0.9)+
geom_line(size = 0.9)+
scale_color_manual(values= c("#01665e","#d8b365"),
labels= c( "Ceará", "Average of Other States"),
name = "")+
ylab("Score")+
xlab("Year")+
scale_x_continuous(labels = c(1995,2000,2005,2010,2015,2020))+
annotate("text", x = 2007, y = 250, label = "TI", color = "#636363", size = 4)+
annotate("text", x = 2018, y = 190, label = "TI + TA", color = "#636363", size = 4)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text = element_text(colour = "#636363"),
axis.line = element_line(colour = "gray"),
panel.border = element_rect(colour = "gray"),
legend.position = "bottom",
panel.spacing = unit(1.1, "lines"),
strip.background = element_rect(fill="white", linetype = "blank"),
text = element_text(family="Helvetica", color ="#636363"))+
facet_grid(vars(grade), vars(subject))
ggarrange(fig_01a, fig_01b, ncol = 1, nrow = 2, common.legend = TRUE, legend = "bottom")
ggsave(filename = "figure01.png", path = "plots", width = 20, height = 15, , units = "cm")