-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_Fig_OwnShare.R
104 lines (84 loc) · 5.23 KB
/
3_Fig_OwnShare.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
# This code uses Own_Data to create 4 figures.
# 1. A time plot showing varying shares of ownership over time used in paper.
# 2. Above plot with years of analysis marked.
# 3. Above time plot with all available data. (not used in paper)
# 4. Two time plots showing ownership proportion in the two subsamples (not used in paper)
# Plot: Share over time ---------------------------------------------------
cols = c("Date","SF65216_p","Banxico_p","SF65211_p","SF65214_p","SF65215_p",
"SF65213_p","SF65218_p")
own_long = melt(Own_Data[Own_Data$Date <= as.Date("2023-12-31") &
Own_Data$Date >= as.Date("2006-01-01"),cols],
id.vars = "Date")
OwnShare_plot = ggplot(data = own_long, aes(x = Date, y = value, color = variable)) +
geom_area(aes(fill = variable)) +
scale_fill_brewer(labels = c("Others","Banxico","Banks","Invst. funds",
"Insurance Co.","Pension funds","Non-residents"),
palette = "Set3") +
guides(color = "none", fill = guide_legend(reverse = TRUE)) +
scale_x_date(date_labels = '%Y', date_breaks = "2 year", expand = c(0, 0))+
scale_y_continuous(expand = c(0,0))+
labs(y = 'Ownership share in govt bonds O/S', x = element_blank())+
theme(axis.text.x = element_text(size = 16),axis.text.y = element_text(size = 14),
axis.title = element_text(size = 16),
legend.title = element_blank(),legend.text = element_text(size = 14),
legend.position = "bottom")
# Plot: Share over time ---------------------------------------------------
OwnShare_plot1 = ggplot(data = own_long, aes(x = Date, y = value, color = variable)) +
geom_area(aes(fill = variable)) +
scale_fill_brewer(labels = c("Others","Banxico","Banks","Invst. funds",
"Insurance Co.","Pension funds","Non-residents"),
palette = "Set3") +
guides(color = "none", fill = guide_legend(reverse = TRUE)) +
geom_rect(aes(xmin=as.Date("2010-01-01"), xmax=as.Date("2011-12-21"),
ymin=-Inf,ymax=Inf),
fill = NA, alpha= 0.01, color ='red', linewidth = 1.2)+
geom_rect(aes(xmin=as.Date("2012-01-11"), xmax=as.Date("2013-12-31"),
ymin=-Inf,ymax=Inf),
fill = NA, alpha= 0.01, color = 'darkgreen', linewidth = 1.2)+
labs(y = 'Ownership share in govt bonds O/S', x = element_blank())+
scale_x_date(date_labels = '%Y', date_breaks = "2 year")+
theme(axis.text = element_text(size = 14), axis.title = element_text(size = 14),
legend.title = element_blank(),legend.text = element_text(size = 14),
legend.position = "bottom")
# Plot: Share over time (all data) ----------------------------------------
own_long_all = melt(Own_Data[,cols],
id.vars = "Date")
ggplot(data = own_long_all, aes(x = Date, y = value, color = variable)) +
geom_area(aes(fill = variable)) +
scale_fill_discrete(labels = c("Others","Banxico","Banks","Invst. funds", "Insurance Co.",
"Pension funds","Non-residents") ) +
guides(color = "none") +
labs(y = 'Ownership share in govt bonds O/S', x = element_blank())+
scale_x_date(date_labels = '%Y', date_breaks = "2 year")+
theme(axis.text = element_text(size = 14), axis.title = element_text(size = 14),
legend.title = element_blank(),legend.text = element_text(size = 14),
legend.position = "bottom")
# Plot: Share in subsamples -----------------------------------------------
own_long1 = melt(Own_Data[Own_Data$Date >= as.Date("2010-01-01") &
Own_Data$Date <= as.Date("2011-12-31"),
cols], id.vars = "Date")
own_long2 = melt(Own_Data[Own_Data$Date >= as.Date("2014-01-01") &
Own_Data$Date <= as.Date("2015-12-31"),
cols], id.vars = "Date")
own_plot1 = ggplot(data = own_long1, aes(x = Date, y = value, color = variable)) +
geom_area(aes(fill = variable)) +
scale_fill_discrete(labels = c("Others","Banxico","Banks","Invst. funds", "Insurance Co.",
"Pension funds","Non-residents") ) +
guides(color = "none") +
labs(x = element_blank(), y = 'Share of bonds O/S',
title = "2010 Jan - 2011 Dec")+
theme(axis.text = element_text(size = 14), axis.title = element_text(size = 14),
axis.text.x = element_blank(),legend.title = element_blank(),
legend.position = "none", legend.text = element_text(size = 14))
own_plot2 = ggplot(data = own_long2, aes(x = Date, y = value, color = variable)) +
geom_area(aes(fill = variable)) +
scale_fill_discrete(labels = c("Others","Banxico","Banks","Invst. funds", "Insurance Co.",
"Pension funds","Non-residents")) +
guides(color = "none") +
labs(x = element_blank(), y = element_blank(),title = "2014 Jan - 2015 Dec")+
theme(axis.text = element_text(size = 14), axis.title = element_text(size = 14),
axis.text.x = element_blank(),legend.title = element_blank(),
legend.position = "none", legend.text = element_text(size = 14))
OwnShareComp_plot = ggarrange(own_plot1, own_plot2, common.legend = T, legend = "bottom")
# Removing excess variables -----------------------------------------------
rm(own_long, own_long_all,own_long1,own_long2)