-
Notifications
You must be signed in to change notification settings - Fork 0
/
wid_data_vis.R
68 lines (59 loc) · 2.5 KB
/
wid_data_vis.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
library(tidyverse)
library(scales)
library(extrafont)
library(directlabels)
loadfonts()
theme_bgs <- function(){
theme_bw() +
theme(text = element_text(family = 'Segoe UI'),
plot.title = element_text(face = 'plain', size = 14),
plot.subtitle = element_text(family = 'Segoe UI Semibold'),
panel.border = element_rect(colour = 'grey85'),
panel.grid.minor = element_line(colour = "grey98", size = 0.25),
axis.title = element_text(family = 'Segoe UI Semibold', size = 12),
axis.text = element_text(size = 12),
axis.ticks = element_blank(),
legend.justification = 'top',
legend.title = element_text(family = 'Segoe UI Semibold'),
strip.background = element_rect(fill = 'grey92'),
strip.text = element_text(family = 'Segoe UI Semibold'))
}
theme_set(theme_bgs())
ineq_data <- read_delim("WID_Data_Metadata//WID_Data_18052019-130037.csv",
delim = ";",
skip = 8,
col_names = c("category",
"year",
"Wealth",
"Income"))
cite_caption <- "Piketty, Thomas; Saez, Emmanuel and Zucman, Gabriel (2016).\nDistributional National Accounts: Methods and Estimates for the United States."
p1 <- ineq_data %>%
gather(variable, value, Wealth, Income) %>%
ggplot(aes(year, value, colour = variable))+
geom_line(size = 1.2)+
geom_point(show.legend = FALSE)+
scale_y_continuous("Share of Total (%)",
labels = percent)+
scale_x_continuous(breaks = seq(0, 3000, 15),
name = "Year")+
scale_colour_brewer(palette = 'Set1',
name = "")+
ggtitle("Rising Inequality Since 1980\nShare of Income and Wealth for Top 10% in USA")+
labs(caption = cite_caption)+
theme(plot.title = element_text(size = 25),
axis.text = element_text(size = 22),
legend.text = element_text(size = 22),
legend.title = element_text(size = 24),
axis.title = element_text(size = 24),
plot.caption = element_text(size = 16),
legend.position = 'none')+
guides(colour = guide_legend(override.aes = list(size = 3)))
p2 <- p1 +
geom_dl(aes(label = variable),
method = list("smart.grid", fontfamily = "Segoe UI", cex = 2))
ggsave(filename = "inequality_data_vis.png",
plot = p2,
width = 12,
height = 8,
units = "in",
dpi = 700)