-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08_appendix_sample_description.R
86 lines (70 loc) · 2.56 KB
/
08_appendix_sample_description.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
"
Distortions
Proportion of High Income, Better Educated, Men in each small group and s.d. of that
"
# Set basedir
setwd(githubdir)
setwd("distortions/")
# Set StringsAsFactors as FALSE
options(stringsAsFactors = FALSE)
# Load dat
dpdat <- read.csv("data/polardata.csv")
# Load libs
library(tidyverse)
props <- dpdat %>%
group_by(pollgroup) %>%
summarize(p_gender = mean(female == 0, na.rm = T), p_better_ed = mean(bettered == 1), p_high_income = mean(highinc == 1))
# Means
round(colMeans(props, na.rm = T), 3)
# s.d.
round(sd(props$p_gender, na.rm = T), 3)
round(sd(props$p_better_ed, na.rm = T), 3)
round(sd(props$p_high_income, na.rm = T), 3)
ggplot(props) +
geom_density(aes(p_gender, y = ..scaled..), alpha = .7) +
theme_bw() +
scale_fill_grey() +
scale_color_grey() +
xlab("Proportion Male") +
ylab("Rel. Freq.") +
theme(axis.text = element_text(size = 7),
axis.ticks = element_blank(),
panel.grid.major.x = element_line(color = "#eeeeee"),
panel.grid.major.y = element_line(color = "#dddddd", linetype = "dotted"),
panel.grid.minor = element_blank(),
plot.margin = unit(c(.5, .5, .5, .5), "cm"),
panel.border = element_rect(0, 0, 0, 0),
legend.title = element_blank())
ggsave("figs/density_p_gender.png", width = 5, height = 5)
ggplot(props) +
geom_density(aes(p_high_income, y = ..scaled..), alpha = .7) +
theme_bw() +
scale_fill_grey() +
scale_color_grey() +
xlab("Proportion Better Educated") +
ylab("Rel. Freq.") +
theme(axis.text = element_text(size = 7),
axis.ticks = element_blank(),
panel.grid.major.x = element_line(color = "#eeeeee"),
panel.grid.major.y = element_line(color = "#dddddd", linetype = "dotted"),
panel.grid.minor = element_blank(),
plot.margin = unit(c(.5, .5, .5, .5), "cm"),
panel.border = element_rect(0, 0, 0, 0),
legend.title = element_blank())
ggsave("figs/density_p_bettered.png", width = 5, height = 5)
ggplot(props) +
geom_density(aes(p_better_ed, y = ..scaled..), alpha = .7) +
theme_bw() +
scale_fill_grey() +
scale_color_grey() +
xlab("Proportion Higher Income") +
ylab("Rel. Freq.") +
theme(axis.text = element_text(size = 7),
axis.ticks = element_blank(),
panel.grid.major.x = element_line(color = "#eeeeee"),
panel.grid.major.y = element_line(color = "#dddddd", linetype = "dotted"),
panel.grid.minor = element_blank(),
plot.margin = unit(c(.5, .5, .5, .5), "cm"),
panel.border = element_rect(0, 0, 0, 0),
legend.title = element_blank())
ggsave("figs/density_p_highinc.png", width = 5, height = 5)