Skip to content

Instantly share code, notes, and snippets.

@ryanburge

ryanburge/rip_fears.R Secret

Created Mar 16, 2020
Embed
What would you like to do?
RIP Fears Post
library(haven)
ch5 <- read_dta("D://chapman2018.dta")
ch5 <- ch5 %>%
mutate(ff1 = car::recode(QN17A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff2 = car::recode(QN17B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff3 = car::recode(QN17C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff4 = car::recode(QN17D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff5 = car::recode(QN17E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff6 = car::recode(QN17F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff7 = car::recode(QN18A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff8 = car::recode(QN18B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff9 = car::recode(QN18C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff10 = car::recode(QN18D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff11 = car::recode(QN18E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff12 = car::recode(QN19A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff13 = car::recode(QN19B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff14 = car::recode(QN19C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff15 = car::recode(QN19D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff16 = car::recode(QN19E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff17 = car::recode(QN19F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff18 = car::recode(QN19G, "1:2=1; 3:4=0; else = NA")) %>%
# mutate(ff19 = car::recode(QN19G, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff20 = car::recode(QN19H, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff21 = car::recode(QN19I, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff22 = car::recode(QN19J, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff23 = car::recode(QN19K, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff24 = car::recode(QN19L, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff25 = car::recode(QN19M, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff26 = car::recode(QN19N, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff27 = car::recode(QN19O, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff28 = car::recode(QN19P, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff29 = car::recode(QN19Q, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff30 = car::recode(QN19R, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff31 = car::recode(QN19S, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff32 = car::recode(QN19T, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff33 = car::recode(QN19U, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff34 = car::recode(QN20A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff35 = car::recode(QN20B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff36 = car::recode(QN20C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff37 = car::recode(QN20D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff38 = car::recode(QN20E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff39 = car::recode(QN20F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff40 = car::recode(QN20G, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff41 = car::recode(QN20H, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff42 = car::recode(QN20I, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff43 = car::recode(QN20J, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff44 = car::recode(QN20K, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff45 = car::recode(QN20L, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff46 = car::recode(QN20M, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff47 = car::recode(QN20N, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff48 = car::recode(QN20O, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff49 = car::recode(QN20P, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff50 = car::recode(QN21A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff51 = car::recode(QN21B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff52 = car::recode(QN21C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff53 = car::recode(QN21D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff54 = car::recode(QN21E, "1:2=1; 3:4=0; else = NA")) %>%
# mutate(fears1 = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14 + f15 + f16 + f17 + f18 + f19 + f20 + f21 + f22 + f23 + f24 + f25 + f26 + f27 + f28 + f29 + f30) %>%
# mutate(fears2 = f31 + f32 + f33 + f34 + f35 + f36 + f37 + f38 + f39 + f40 + f41 + f42 + f43 + f44 + f45 + f46 + f47 + f48 + f49 + f50 + f51 + f52 + f53 + f54) %>%
# mutate(fears = fears1 + fears2) %>%
mutate(relig = car::recode(religion, "1=1; 5=1; 6=1; 8=1; 13=1; 14=1; 15=1; 22=1; 23=1; 24=1; 25=1; 26=1; 27=1; 30=1; 2=2; 90=10; 95=10; 96=10")) %>%
mutate(relig = frcode(relig == 1 ~ "Protestant",
relig == 2 ~ "Catholic",
relig == 10 ~ "No Religion")) %>%
mutate(ideo = 8 - QN5)
rr <- ch5 %>%
select(relig, starts_with("ff")) %>%
group_by(relig) %>%
na.omit() %>%
summarise_all(funs(mean))
rr <- melt(rr) %>% as_tibble()
lab <- rr %>%
mutate(fear = frcode(variable == "ff1" ~ "Spouse Cheating",
variable == "ff2" ~ "Walking Alone at Night",
variable == "ff3" ~ "Others Talking Behind Your Back",
variable == "ff4" ~ "Being Fooled by Fake News",
variable == "ff5" ~ "Sexual Harrassment at Work",
variable == "ff6" ~ "Sharing Transgender Bathroom",
variable == "ff7" ~ "Computers Replacing People",
variable == "ff8" ~ "Technology I Don't Understand",
variable == "ff9" ~ "Cyber-Terrorism",
variable == "ff10"~ "Corporate Tracking of Personal Data",
variable == "ff11"~ "Govt. Tracking of Personal Data",
variable == "ff12"~ "Earthquake",
variable == "ff13"~ "Hurricane",
variable == "ff14"~ "Tornado",
variable == "ff15"~ "Flood",
variable == "ff16"~ "Blizzard",
variable == "ff17"~ "Drought",
variable == "ff18"~ "Wildfire",
variable == "ff20"~ "Volcanic Eruption",
variable == "ff21"~ "Collapse of Electrical Grid",
variable == "ff22"~ "Nuclear Attack",
variable == "ff23"~ "Nuclear Accident",
variable == "ff24"~ "Financial Collapse",
variable == "ff25"~ "Pandemic",
variable == "ff26"~ "Civil Unrest",
variable == "ff27"~ "U.S. in World War",
variable == "ff28"~ "Whites Not Being Majority",
variable == "ff29"~ "Illegal Immigration",
variable == "ff30"~ "Biological Warfare",
variable == "ff31"~ "Terrorist Attack",
variable == "ff32"~ "N. Korea Nuclear Attack",
variable == "ff33"~ "Iran Nuclear Attack",
variable == "ff34"~ "Blood",
variable == "ff35"~ "Needles",
variable == "ff36"~ "Insects",
variable == "ff37"~ "Reptiles",
variable == "ff38"~ "Animals",
variable == "ff39"~ "Sharks",
variable == "ff40"~ "Clowns",
variable == "ff41"~ "Germs",
variable == "ff42"~ "Deep Lakes/Oceans",
variable == "ff43"~ "Flying",
variable == "ff44"~ "Ghosts",
variable == "ff45"~ "Heights",
variable == "ff46"~ "Public Speaking",
variable == "ff47"~ "Small Enclosed Spaces",
variable == "ff48"~ "Zombies",
variable == "ff49"~ "Strangers",
variable == "ff50"~ "Satan",
variable == "ff51"~ "Demons",
variable == "ff52"~ "God",
variable == "ff53"~ "Hell",
variable == "ff54"~ "Armageddon"))
lab %>%
mutate(value = round(value, 2)) %>%
filter(relig == "Protestant") %>%
filter(fear != "NA") %>%
ggplot(., aes(x = reorder(fear, value), y = value, fill = value)) +
geom_col(color = "black") +
coord_flip() +
theme_gg("Abel") +
y_pct() +
lab_bar(type = value, pos = .02, sz = 3, top = FALSE) +
scale_fill_gradient(low = "#333333", high = "#dd1818") +
labs(x = "Fear", y = "Percent Saying 'Afraid/Very Afraid'", title = "What Are Protestants Afraid Of?", caption = "@ryanburge\nData: Chapman Survey of American Fears (2018)") +
ggsave("E://fears_protestants.png", type = "cairo-png", width = 8, height = 10)
lab %>%
mutate(value = round(value, 2)) %>%
filter(relig == "Catholic") %>%
filter(fear != "NA") %>%
ggplot(., aes(x = reorder(fear, value), y = value, fill = value)) +
geom_col(color = "black") +
coord_flip() +
theme_gg("Abel") +
y_pct() +
lab_bar(type = value, pos = .02, sz = 3, top = FALSE) +
scale_fill_gradient(low = "#333333", high = "#dd1818") +
labs(x = "Fear", y = "Percent Saying 'Afraid/Very Afraid'", title = "What Are Catholics Afraid Of?", caption = "@ryanburge\nData: Chapman Survey of American Fears (2018)") +
ggsave("E://fears_cath.png", type = "cairo-png", width = 8, height = 10)
lab %>%
mutate(value = round(value, 2)) %>%
filter(relig == "No Religion") %>%
filter(fear != "NA") %>%
ggplot(., aes(x = reorder(fear, value), y = value, fill = value)) +
geom_col(color = "black") +
coord_flip() +
theme_gg("Abel") +
y_pct() +
lab_bar(type = value, pos = .02, sz = 3, top = FALSE) +
scale_fill_gradient(low = "#333333", high = "#dd1818") +
labs(x = "Fear", y = "Percent Saying 'Afraid/Very Afraid'", title = "What Are the Nones Afraid Of?", caption = "@ryanburge\nData: Chapman Survey of American Fears (2018)") +
ggsave("E://fears_nones.png", type = "cairo-png", width = 8, height = 10)
prot <- lab %>%
filter(relig == "Protestant")
cath <- lab %>%
filter(relig == "Catholic")
none <- lab %>%
filter(relig == "No Religion")
graph <- bind_cols(prot, cath, none) %>%
select(`Protestants` = value,
`Catholics` = value1,
`Nones` = value2,
type = fear)
g1 <- ggplot() +
# reshape the data frame & get min value so you can draw an eye-tracking line (this is one geom)
geom_segment(
data = gather(graph, measure, val, -type) %>%
group_by(type) %>%
top_n(-1) %>%
slice(1) %>%
ungroup(),
aes(x = 0, xend = val, y = type, yend = type),
linetype = "dotted", size = 0.5, color = "gray80"
) +
# reshape the data frame & get min/max category values so you can draw the segment (this is another geom)
geom_segment(
data = gather(graph, measure, val, -type) %>%
group_by(type) %>%
summarise(start = range(val)[1], end = range(val)[2]) %>%
ungroup(),
aes(x = start, xend = end, y = type, yend = type),
color = "gray80", size = 2
) +
# reshape the data frame & plot the points
geom_point(
data = gather(graph, measure, value, -type),
aes(value, type, color = measure), shape = 21, stroke =2, fill = "white", size = 3
)
g1 +
scale_color_tableau() +
scale_x_continuous(labels = scales::percent, limits = c(0, .65)) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
labs(x = "Percent Who Say Afraid/Very Afraid", y = "", title = "Fear Based on Religious Affilation", caption = "@ryanburge\nData: Chapman Survey of American Fears 2018") +
ggsave("E://threepoint_fears.png", type = "cairo-png", width = 10, height = 10)
## Attendance Bells ####
ch5 <- read_dta("D://chapman2018.dta")
ch5 <- ch5 %>%
mutate(ff1 = car::recode(QN17A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff2 = car::recode(QN17B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff3 = car::recode(QN17C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff4 = car::recode(QN17D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff5 = car::recode(QN17E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff6 = car::recode(QN17F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff7 = car::recode(QN18A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff8 = car::recode(QN18B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff9 = car::recode(QN18C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff10 = car::recode(QN18D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff11 = car::recode(QN18E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff12 = car::recode(QN19A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff13 = car::recode(QN19B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff14 = car::recode(QN19C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff15 = car::recode(QN19D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff16 = car::recode(QN19E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff17 = car::recode(QN19F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff18 = car::recode(QN19G, "1:2=1; 3:4=0; else = NA")) %>%
# mutate(ff19 = car::recode(QN19G, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff20 = car::recode(QN19H, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff21 = car::recode(QN19I, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff22 = car::recode(QN19J, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff23 = car::recode(QN19K, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff24 = car::recode(QN19L, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff25 = car::recode(QN19M, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff26 = car::recode(QN19N, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff27 = car::recode(QN19O, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff28 = car::recode(QN19P, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff29 = car::recode(QN19Q, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff30 = car::recode(QN19R, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff31 = car::recode(QN19S, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff32 = car::recode(QN19T, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff33 = car::recode(QN19U, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff34 = car::recode(QN20A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff35 = car::recode(QN20B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff36 = car::recode(QN20C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff37 = car::recode(QN20D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff38 = car::recode(QN20E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff39 = car::recode(QN20F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff40 = car::recode(QN20G, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff41 = car::recode(QN20H, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff42 = car::recode(QN20I, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff43 = car::recode(QN20J, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff44 = car::recode(QN20K, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff45 = car::recode(QN20L, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff46 = car::recode(QN20M, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff47 = car::recode(QN20N, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff48 = car::recode(QN20O, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff49 = car::recode(QN20P, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff50 = car::recode(QN21A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff51 = car::recode(QN21B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff52 = car::recode(QN21C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff53 = car::recode(QN21D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff54 = car::recode(QN21E, "1:2=1; 3:4=0; else = NA")) %>%
# mutate(fears1 = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14 + f15 + f16 + f17 + f18 + f19 + f20 + f21 + f22 + f23 + f24 + f25 + f26 + f27 + f28 + f29 + f30) %>%
# mutate(fears2 = f31 + f32 + f33 + f34 + f35 + f36 + f37 + f38 + f39 + f40 + f41 + f42 + f43 + f44 + f45 + f46 + f47 + f48 + f49 + f50 + f51 + f52 + f53 + f54) %>%
# mutate(fears = fears1 + fears2) %>%
mutate(relig = car::recode(religion, "1=1; 5=1; 6=1; 8=1; 13=1; 14=1; 15=1; 22=1; 23=1; 24=1; 25=1; 26=1; 27=1; 30=1; 2=2; 90=10; 95=10; 96=10")) %>%
mutate(relig = frcode(relig == 1 ~ "Protestant",
relig == 2 ~ "Catholic",
relig == 10 ~ "No Religion")) %>%
mutate(attend = QN2)
aa <- ch5 %>%
# filter(relig == "Protestant" | relig == "Catholic") %>%
mutate(att = frcode(attend == 1 ~ "Never",
attend == 8 | attend == 9 ~ "Weekly or More")) %>%
select(att, starts_with("ff")) %>%
group_by(att) %>%
na.omit() %>%
summarise_all(funs(mean))
aa <- melt(aa) %>% as_tibble()
lab <- aa %>%
mutate(fear = frcode(variable == "ff1" ~ "Spouse Cheating",
variable == "ff2" ~ "Walking Alone at Night",
variable == "ff3" ~ "Others Talking Behind Your Back",
variable == "ff4" ~ "Being Fooled by Fake News",
variable == "ff5" ~ "Sexual Harrassment at Work",
variable == "ff6" ~ "Sharing Transgender Bathroom",
variable == "ff7" ~ "Computers Replacing People",
variable == "ff8" ~ "Technology I Don't Understand",
variable == "ff9" ~ "Cyber-Terrorism",
variable == "ff10"~ "Corporate Tracking of Personal Data",
variable == "ff11"~ "Govt. Tracking of Personal Data",
variable == "ff12"~ "Earthquake",
variable == "ff13"~ "Hurricane",
variable == "ff14"~ "Tornado",
variable == "ff15"~ "Flood",
variable == "ff16"~ "Blizzard",
variable == "ff17"~ "Drought",
variable == "ff18"~ "Wildfire",
variable == "ff20"~ "Volcanic Eruption",
variable == "ff21"~ "Collapse of Electrical Grid",
variable == "ff22"~ "Nuclear Attack",
variable == "ff23"~ "Nuclear Accident",
variable == "ff24"~ "Financial Collapse",
variable == "ff25"~ "Pandemic",
variable == "ff26"~ "Civil Unrest",
variable == "ff27"~ "U.S. in World War",
variable == "ff28"~ "Whites Not Being Majority",
variable == "ff29"~ "Illegal Immigration",
variable == "ff30"~ "Biological Warfare",
variable == "ff31"~ "Terrorist Attack",
variable == "ff32"~ "N. Korea Nuclear Attack",
variable == "ff33"~ "Iran Nuclear Attack",
variable == "ff34"~ "Blood",
variable == "ff35"~ "Needles",
variable == "ff36"~ "Insects",
variable == "ff37"~ "Reptiles",
variable == "ff38"~ "Animals",
variable == "ff39"~ "Sharks",
variable == "ff40"~ "Clowns",
variable == "ff41"~ "Germs",
variable == "ff42"~ "Deep Lakes/Oceans",
variable == "ff43"~ "Flying",
variable == "ff44"~ "Ghosts",
variable == "ff45"~ "Heights",
variable == "ff46"~ "Public Speaking",
variable == "ff47"~ "Small Enclosed Spaces",
variable == "ff48"~ "Zombies",
variable == "ff49"~ "Strangers",
variable == "ff50"~ "Satan",
variable == "ff51"~ "Demons",
variable == "ff52"~ "God",
variable == "ff53"~ "Hell",
variable == "ff54"~ "Armageddon"))
never <- lab %>%
filter(att == "Never") %>%
select(never = value, fear)
week <- lab %>%
filter(att == "Weekly or More") %>%
select(week = value)
bells <- bind_cols(never, week)
bells %>%
ggplot(., aes(x= never, xend = week, y = reorder(fear, week))) +
geom_dumbbell(colour_x = "firebrick2", colour_xend = "darkorchid", size = .75, size_x = 1.75, size_xend = 1.75, shape = 21, stroke = 2, fill = "white") +
theme_gg("Abel") +
labs(x= "Percent Saying 'Afraid/Very Afraid'", y = "", title = "How Do Fears Differ Based on Church Attendance?", caption = "@ryanburge\nData: Chapman Survey of American Fears (2018)")+
scale_fill_d3(palette = "category20") +
scale_color_d3(palette = "category20") +
theme(legend.position = c(.8, .2)) +
x_pct() +
geom_text(data = filter(bells, fear == "Iran Nuclear Attack"), aes(x= never, y = fear, label = "Never"), hjust = 1.2, family = "font", size = 5) +
geom_text(data = filter(bells, fear == "Iran Nuclear Attack"), aes(x= week, y = fear, label = "Weekly"), hjust = -.15, family = "font", size = 5) +
geom_text(data = filter(bells, fear == "Flying"), aes(x= never, y = fear, label = "Never"), hjust = -.25, family = "font", size = 5) +
geom_text(data = filter(bells, fear == "Flying"), aes(x= week, y = fear, label = "Weekly"), hjust = 1.2, family = "font", size = 5) +
ggsave("E://fear_att_bell.png", type = "cairo-png", width = 10, height = 10)
ch5 <- ch5 %>%
mutate(ff1 = car::recode(QN17A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff2 = car::recode(QN17B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff3 = car::recode(QN17C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff4 = car::recode(QN17D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff5 = car::recode(QN17E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff6 = car::recode(QN17F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff7 = car::recode(QN18A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff8 = car::recode(QN18B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff9 = car::recode(QN18C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff10 = car::recode(QN18D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff11 = car::recode(QN18E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff12 = car::recode(QN19A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff13 = car::recode(QN19B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff14 = car::recode(QN19C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff15 = car::recode(QN19D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff16 = car::recode(QN19E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff17 = car::recode(QN19F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff18 = car::recode(QN19G, "1:2=1; 3:4=0; else = NA")) %>%
# mutate(ff19 = car::recode(QN19G, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff20 = car::recode(QN19H, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff21 = car::recode(QN19I, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff22 = car::recode(QN19J, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff23 = car::recode(QN19K, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff24 = car::recode(QN19L, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff25 = car::recode(QN19M, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff26 = car::recode(QN19N, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff27 = car::recode(QN19O, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff28 = car::recode(QN19P, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff29 = car::recode(QN19Q, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff30 = car::recode(QN19R, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff31 = car::recode(QN19S, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff32 = car::recode(QN19T, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff33 = car::recode(QN19U, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff34 = car::recode(QN20A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff35 = car::recode(QN20B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff36 = car::recode(QN20C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff37 = car::recode(QN20D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff38 = car::recode(QN20E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff39 = car::recode(QN20F, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff40 = car::recode(QN20G, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff41 = car::recode(QN20H, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff42 = car::recode(QN20I, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff43 = car::recode(QN20J, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff44 = car::recode(QN20K, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff45 = car::recode(QN20L, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff46 = car::recode(QN20M, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff47 = car::recode(QN20N, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff48 = car::recode(QN20O, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff49 = car::recode(QN20P, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff50 = car::recode(QN21A, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff51 = car::recode(QN21B, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff52 = car::recode(QN21C, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff53 = car::recode(QN21D, "1:2=1; 3:4=0; else = NA")) %>%
mutate(ff54 = car::recode(QN21E, "1:2=1; 3:4=0; else = NA")) %>%
mutate(fears1 = ff1 + ff2 + ff3 + ff4 + ff5 + ff6 + ff7 + ff8 + ff9 + ff10 + ff11 + ff12 + ff13 + ff14 + ff15 + ff16 + ff17 + ff18 + ff20 + ff21 + ff22 + ff23 + ff24 + ff25 + ff26 + ff27 + ff28 + ff29 + ff30) %>%
mutate(fears2 = ff31 + ff32 + ff33 + ff34 + ff35 + ff36 + ff37 + ff38 + ff39 + ff40 + ff41 + ff42 + ff43 + ff44 + ff45 + ff46 + ff47 + ff48 + ff49 + ff50 + ff51 + ff52 + ff53 + ff54) %>%
mutate(fears = fears1 + fears2) %>%
mutate(relig = car::recode(religion, "1=1; 5=1; 6=1; 8=1; 13=1; 14=1; 15=1; 22=1; 23=1; 24=1; 25=1; 26=1; 27=1; 30=1; 2=2; 90=10; 95=10; 96=10")) %>%
mutate(relig = frcode(relig == 1 ~ "Protestant",
relig == 2 ~ "Catholic")) %>%
mutate(pid3 = car::recode(QN5, "5:7=1; 4=2; 1:3=3")) %>%
mutate(rep = car::recode(pid3, "3=1; else =0")) %>%
mutate(attend = QN2) %>%
mutate(white = car::recode(race, "1=1; else = 0")) %>%
mutate(male = car::recode(sex, "1=1; else =0"))
reg1 <- lm(fears ~ attend*relig + rep + age + white + male + educ, data = ch5)
gg1 <- interact_plot(reg1, pred= attend, modx = relig, int.width = .76, interval = TRUE)
gg1 +
scale_color_manual(values = c("#E1585A", "#4F7AA7")) +
scale_fill_manual(values = c("#E1585A", "#4F7AA7")) +
theme_gg("Abel") +
add_text(x = 5, y = 16, word = "Catholics", sz = 4) +
add_text(x = 7, y = 13, word = "Protestants", sz =4) +
scale_x_continuous(breaks = c(1, 2, 3, 4, 5, 6, 7, 8, 9), labels = c("Never", "", "", "Once a Year", "", "", "2-3x a Month", "", "Weekly+")) +
labs(x = "Church Attendance", y = "Predicted Number of Fears", title = "Does Church Attendance Drive Up Fear?", caption = "@ryanburge\nData: Chapman Survey of American Fears (2018)") +
ggsave("E://fears_interaction.png", width = 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment