cols = c("misinfo_infosource_printed", "misinfo_infosource_onlinenews",
"misinfo_infosource_tv")
dat$infosource_traditional = rowMeans(dat[, cols], na.rm=TRUE)
dat$infodiff_socmed_traditional = dat$infosource_socmed - dat$infosource_traditional
cols = c("infosource_instagram2pt", "infosource_facebook2pt",
"infosource_twitter2pt", "infosource_tiktok2pt")
dat$infosource_socmed04 = rowSums(dat[, cols], na.rm=TRUE)
cols = c("misinfo_infosource_printed", "misinfo_infosource_tv", "misinfo_infosource_onlinenews",
"misinfo_infosource_instagram", "misinfo_infosource_facebook",
"misinfo_infosource_twitter", "misinfo_infosource_tiktok")
dat$infosource_all = rowMeans(dat[, cols], na.rm=TRUE)
############################################################################################
### trust on different information sources
dat$trustinfo_printed2pt = car::recode(dat$misinfo_trustsource_printed,
"1:2 = 0; 3:4=1")
dat$trustinfo_tv2pt = car::recode(dat$misinfo_infosource_tv,
"1:2 = 0; 3:4=1")
dat$trustinfo_onlinenews2pt = car::recode(dat$misinfo_trustsource_online,
"1:2 = 0; 3:4=1")
dat$trustinfo_facebook2pt = car::recode(dat$misinfo_trustsource_facebook,
"1:2 = 0; 3:4=1")
dat$trustinfo_twitter2pt = car::recode(dat$misinfo_trustsource_twitter,
"1:2 = 0; 3:4=1")
dat$trustinfo_tiktok2pt = car::recode(dat$misinfo_trustsource_tiktok,
"1:2 = 0; 3:4=1")
dat$trustinfo_instagram2pt = car::recode(dat$misinfo_trustsource_instagram,
"1:2 = 0; 3:4=1")
dat$trustinfo_fb_printed = as.numeric(dat$misinfo_trustsource_facebook > dat$misinfo_trustsource_printed)
dat$trustinfo_ig_printed = as.numeric(dat$misinfo_trustsource_instagram > dat$misinfo_trustsource_printed)
dat$trustinfo_twitter_printed = as.numeric(dat$misinfo_trustsource_twitter > dat$misinfo_trustsource_printed)
dat$trustinfo_tiktok_printed = as.numeric(dat$misinfo_trustsource_tiktok > dat$misinfo_trustsource_printed)
############################################################################################
### electoral integrity
dat$elecint_event_integrity[dat$week > 11] = dat$elecint_eventb_integrity[dat$week > 11]
dat$elecint_event_opposition[dat$week > 11] = dat$elecint_eventb_opposition[dat$week > 11]
dat$elecint_event_bribe[dat$week > 11] = dat$elecint_eventb_bribe[dat$week > 11]
dat$elecint_event_partisanship[dat$week > 11] = dat$elecint_eventb_partisanship[dat$week > 11]
dat$elecint_event_threat[dat$week > 11] = dat$elecint_eventb_threat[dat$week > 11]
dat$elecint_event_opposition = car::recode(dat$elecint_event_opposition,
"1=4; 2=3; 3=2; 4=1")
dat$elecint_event_bribe = car::recode(dat$elecint_event_bribe,
"1=4; 2=3; 3=2; 4=1")
dat$elecint_event_partisanship = car::recode(dat$elecint_event_partisanship,
"1=4; 2=3; 3=2; 4=1")
dat$elecint_event_threat = car::recode(dat$elecint_event_threat,
"1=4; 2=3; 3=2; 4=1")
cols = c("elecint_event_opposition", "elecint_event_bribe", "elecint_event_partisanship",
"elecint_event_threat")
dat$elecintegrity = rowMeans(dat[, cols], na.rm=TRUE)
############################################################################################
### political knowledge
dat$knowledge_review01 = ifelse(dat$knowledge_review == 1, 1, 0)
dat$knowledge_amendment01 = ifelse(dat$knowledge_amendment == 4, 1, 0)
dat$knowledge_mpr01 = ifelse(dat$knowledge_mpr == 1, 1, 0)
dat$knowledge_vp01 = ifelse(dat$knowledge_vp == 1, 1, 0)
dat$knowledge_jkwparty01 = ifelse(dat$knowledge_jkwparty == 1, 1, 0)
dat$knowledge_dprtermlim01 = ifelse(dat$knowledge_dprtermlim == 5, 1, 0)
dat$knowledge_elecdispute01 = ifelse(dat$knowledge_elecdisput == 1, 1, 0)
dat$knowledge_unsc01 = ifelse(dat$knowledge_unsc == 5, 1, 0)
dat$knowledge_leader01 = ifelse(dat$knowledge_leader == 1, 1, 0)
cols = c("knowledge_review01", "knowledge_amendment01", "knowledge_mpr01", "knowledge_vp01",
"knowledge_jkwparty01", "knowledge_dprtermlim01", "knowledge_elecdispute01",
"knowledge_unsc01", "knowledge_leader01")
# dat[,cols] = apply(dat[,cols], 2, function(x) ifelse(is.na(x), 0, x))
dat$polknowledge = rowSums(dat[,cols], na.rm=TRUE)
cols = c("knowledge_review01", "knowledge_amendment01", "knowledge_mpr01", "knowledge_dprtermlim01", "knowledge_elecdispute01")
dat$polknowledge5 = rowSums(dat[,cols])
dat$polknowledge[dat$week %% 2 == 1] = NA
dat$polknowledge5[dat$week %% 2 == 1] = NA
dat$polknowledge[dat$week > 18] = NA
dat$polknowledge5[dat$week > 18] = NA
############################################################################################
### institutional trust
cols = c("trustinst_inst_president", "trustinst_inst_tni", "trustinst_inst_polri", "trustinst_inst_dpr",
"trustinst_inst_mk", "trustinst_inst_kpu")
dat$trustinst = rowMeans(dat[, cols], na.rm=TRUE)
dat$trustinst_inst_president2pt = car::recode(dat$trustinst_inst_president,
"1:2=0; 3:4=1")
dat$trustinst_inst_tni2pt = car::recode(dat$trustinst_inst_tni,
"1:2=0; 3:4=1")
dat$trustinst_inst_polri2pt = car::recode(dat$trustinst_inst_polri,
"1:2=0; 3:4=1")
dat$trustinst_inst_dpr2pt = car::recode(dat$trustinst_inst_dpr,
"1:2=0; 3:4=1")
dat$trustinst_inst_mk2pt = car::recode(dat$trustinst_inst_mk,
"1:2=0; 3:4=1")
dat$trustinst_inst_kpu2pt = car::recode(dat$trustinst_inst_kpu,
"1:2=0; 3:4=1")
############################################################################################
### civil society trust
cols = c("trustciv_groups_journalist", "trustciv_groups_religiousleader", "trustciv_groups_scientist",
"trustciv_groups_activist")
dat$trustcivsoc = rowMeans(dat[, cols], na.rm=TRUE)
cols = c("trustciv_groups_journalist", "trustciv_groups_scientist",
"trustciv_groups_activist")
dat$trustcivsoc_norel = rowMeans(dat[, cols], na.rm=TRUE)
############################################################################################
### support for democracy
dat$democ_satisfied01 = (dat$democ_satisfied-1)/3
dat$democ_suitable01 = (dat$democ_suitable-1)/5
dat$democ_satisfied2pt = car::recode(dat$democ_satisfied,
"1:2 = 0; 3:4 = 1")
dat$democ_suitable2pt = car::recode(dat$democ_suitable,
"1:3 = 0; 4:6 = 1")
dat$democ_characteristic_election2pt = car::recode(dat$democ_characteristic_election,
"1:4 = 0; 5:6 = 1")
dat$democ_characteristic_military2pt = car::recode(dat$democ_characteristic_military,
"1:4 = 0; 5:6 = 1")
dat$democ_characteristic_obey2pt = car::recode(dat$democ_characteristic_obey,
"1:4 = 0; 5:6 = 1")
dat$democ_characteristic_religion2pt = car::recode(dat$democ_characteristic_religion,
"1:4 = 0; 5:6 = 1")
dat$democ_characteristic_rights2pt = car::recode(dat$democ_characteristic_rights,
"1:4 = 0; 5:6 = 1")
############################################################################################
### political participation
dat$polint_activities_protest2pt = car::recode(dat$polint_activities_protest,
"1:3=0; 4=1")
dat$polint_activities_persuade2pt = car::recode(dat$polint_activities_persuade,
"1:3=0; 4=1")
dat$polint_activities_campaign2pt = car::recode(dat$polint_activities_campaign,
"1:3=0; 4=1")
dat$polactivities_elect = rowSums(dat[, c("polint_activities_persuade2pt", "polint_activities_campaign2pt")], na.rm=TRUE)
dat$polactivities_all = rowSums(dat[, c("polint_activities_protest2pt",
"polint_activities_persuade2pt",
"polint_activities_campaign2pt")], na.rm=TRUE)
dat$polint_interest01 = (dat$polint_interest-1)/3
dat$polint_discussion01 = (dat$polint_discussion-1)/2
dat$polint_interest2pt = NA
dat$polint_interest2pt[dat$polint_interest %in% c(1:2)] = 0
dat$polint_interest2pt[dat$polint_interest %in% c(3:4)] = 1
dat$polint_interest2ptlab = car::recode(dat$polint_interest2pt,
"0 = 'Low Interest';
1 = 'High Interest'")
############################################################################################
### political Islam
cols = c("polrel_polislam_priority", "polrel_polislam_ulama", "polrel_polislam_law")
dat$polislam = rowMeans(dat[,cols], na.rm=TRUE)
dat$polislam01 = (dat$polislam-1)/3
############################################################################################
### religiosity
cols_muslim = c("religiosity_muslim_quran", "religiosity_muslim_shalat", "religiosity_muslim_mosque", "religiosity_muslim_recitation")
cols_nonmuslim = c("religiosity_nonmus_pray", "religiosity_nonmus_recitation", "religiosity_nonmus_worshiphouse")
dat$religiosity_muslim = rowMeans(dat[,cols_muslim], na.rm=TRUE)
dat$religiosity_nonmuslim = rowMeans(dat[,cols_nonmuslim], na.rm=TRUE)
dat$religiosity = rowMeans(dat[,c(cols_muslim, cols_nonmuslim)], na.rm=TRUE)
dat$religiosity01 = (dat$religiosity-1)/5
dat$religiosity_muslim_mosque01 = (dat$religiosity_muslim_mosque-1)/5
dat$religiosity_muslim_quran01 = (dat$religiosity_muslim_quran-1)/5
dat$religiosity_muslim_shalat01 = (dat$religiosity_muslim_shalat-1)/5
dat$religiosity_muslim_recitation01 = (dat$religiosity_muslim_recitation-1)/5
############################################################################################
### religious intolerance
cols = c("relintol_muslim_worship", "relintol_muslim_worshiphouse", "relintol_muslim_leader", "relintol_muslim_rt",
"relintol_nonmuslim_worship", "relintol_nonmuslim_worshiphouse", "relintol_nonmuslim_leader", "relintol_nonmuslim_rt",
"relintol_neighbor")
dat$relintol = rowMeans(dat[,cols], na.rm=TRUE)
dat$relintol01 = (dat$relintol-1)/3
############################################################################################
### intoleran behavior
dat$intolbehav_muslim = as.numeric(dat$tolbehav_muslim == 0)
dat$intolbehav_nonmuslim = as.numeric(dat$tolbehav_nonmuslim == 0)
dat$intolbehav = rowMeans(dat[, c("intolbehav_muslim", "intolbehav_nonmuslim")], na.rm=TRUE)
############################################################################################
### religiosity
cols_muslim = c("religiosity_muslim_quran", "religiosity_muslim_shalat", "religiosity_muslim_mosque")
cols_nonmuslim = c("religiosity_nonmus_pray", "religiosity_nonmus_recitation", "religiosity_nonmus_worshiphouse")
dat$religiosity_muslim = rowMeans(dat[,cols_muslim], na.rm=TRUE)
dat$religiosity_nonmuslim = rowMeans(dat[,cols_nonmuslim], na.rm=TRUE)
dat$religiosity = rowMeans(dat[,c(cols_muslim, cols_nonmuslim)], na.rm=TRUE)
############################################################################################
### ethnoreligious feelings
cols_old = c("feelethno_groups_agnostic", "feelethno_groups_arab", "feelethno_groups_islam",
"feelethno_groups_christian", "feelethno_groups_tionghoa")
cols_new = c("dislike_agnostic", "dislike_arab", "dislike_islam",
"dislike_christian", "dislike_tionghoa")
dat[,cols_new] = apply(dat[,cols_old], 2, function(x) car::recode(x, "1=5; 2=4; 3=3; 4=2; 5=1"))
cols_new = c("dislike_agnostic2pt", "dislike_arab2pt", "dislike_islam2pt",
"dislike_christian2pt", "dislike_tionghoa2pt")
dat[,cols_new] = apply(dat[,cols_old], 2, function(x) car::recode(x, "1=1; 2=1; 3=0; 4=0; 5=0"))
### feeling ingroup - outgroup (Christians and Muslims only)
dat$feel_relingroup = dat$feel_reloutgroup = NA
dat$feel_relingroup[dat$demog_religion == 1] =
dat$feelethno_groups_islam[dat$demog_religion == 1]
dat$feel_relingroup[dat$demog_religion %in% c(2:3)] =
dat$feelethno_groups_christian[dat$demog_religion %in% c(2:3)]
dat$feel_reloutgroup[dat$demog_religion == 1] =
dat$feelethno_groups_christian[dat$demog_religion == 1]
dat$feel_reloutgroup[dat$demog_religion %in% c(2:3)] =
dat$feelethno_groups_islam[dat$demog_religion  %in% c(2:3)]
############################################################################################
### country feelings
cols = c("feelcty_countries_malaysia", "feelcty_countries_us", "feelcty_countries_china", "feelcty_countries_arab",
"feelcty_countries_australia", "feelcty_countries_india")
dat$feelcty = rowMeans(dat[,cols], na.rm=TRUE)
############################################################################################
### inclusive sermons
dat$polrel_sermoninclusive = as.numeric(rowSums(dat[, c("polrel_sermontoleran", "polrel_sermonunity")], na.rm=TRUE) >= 1)
############################################################################################
### bonding
dat$net_friendrel2pt = car::recode(dat$net_friendrel, "1:4=0; 5=1")
dat$net_neighborrel2pt = car::recode(dat$net_neighborrel, "1:4=0; 5=1")
dat$net_workrel2pt = car::recode(dat$net_workrel, "1:4=0; 5=1")
dat$net_context2pt = as.numeric((dat$net_neighborrel2pt & dat$net_workrel2pt) |
(is.na(dat$net_neighborrel2pt) & dat$net_workrel2pt == 1) |
(dat$net_neighborrel2pt == 1 & is.na(dat$net_workrel2pt)))
############################################################################################
### name generator
w32 = read.xlsx("C:/Dropbox/Work/Research In Progress/SIKAP/Weekly Data/namegen_w32.xlsx", sheet = 1)
w32 = w32[,c(1,2,3,4,5,7)]      # remove name 5
w33 = read.xlsx("C:/Dropbox/Work/Research In Progress/SIKAP/Weekly Data/namegen_w33.xlsx", sheet = 1)
w34 = read.xlsx("C:/Dropbox/Work/Research In Progress/SIKAP/Weekly Data/namegen_w34.xlsx", sheet = 1)
w35 = read.xlsx("C:/Dropbox/Work/Research In Progress/SIKAP/Weekly Data/namegen_w35.xlsx", sheet = 1)
w36 = read.xlsx("C:/Dropbox/Work/Research In Progress/SIKAP/Weekly Data/namegen_w36.xlsx", sheet = 1)
w37 = read.xlsx("C:/Dropbox/Work/Research In Progress/SIKAP/Weekly Data/namegen_w37.xlsx", sheet = 1)
flagged = bind_rows(w32,w33,w34,w35,w36,w37)
flagged = subset(flagged, flag == 1)
index = which(dat$pid %in% flagged$PID)
dat$namegen_flag = 0
dat$namegen_flag[index] = 1
dat$net_rel_1 = as.numeric(dat$net_rel_1)
################################### social sampling #####################################
dat$sosa_voters_anies = dat$sosa_voters_1
table(dat$sosa_voters_1)
source("./extras/packages.R")
library(summarytools)
library(ggridges)
library(nnet)
rm(list = ls())
load("sikap_w1_w58.Rdata")
dat <- haven::zap_labels(dat)
source("./extras/prepare_vars.R")
source("./extras/packages.R")
library(summarytools)
library(ggridges)
library(nnet)
rm(list = ls())
load("sikap_w1_w58.Rdata")
dat <- haven::zap_labels(dat)
source("./extras/prepare_vars.R")
table(dat$week)
dat$weekfac = factor(dat$week,
levels = c(min(dat$week):max(dat$week)))
nrow(dat)
length(unique(dat$pid))
t = table(dat$counter)
t - c(t[-1],0)
vec_pid = dat$pid[dat$counter == 2]
df = dat
df = subset(df, pid %in% vec_pid & counter %in% c(1,2,3,4,5,6))
df = df[, c("pid", "week", "counter")]
d = df %>% group_by(pid) %>%
summarise(week1 = mean(week[counter == 1]),
week2 = mean(week[counter == 2], na.rm=TRUE),
week3 = mean(week[counter == 3], na.rm=TRUE),
week4 = mean(week[counter == 4], na.rm=TRUE),
week5 = mean(week[counter == 5], na.rm=TRUE),
week6 = mean(week[counter == 6], na.rm=TRUE),
diff12 = week2 - week1,
diff23 = week3 - week2,
diff34 = week4 - week3,
diff45 = week5 - week4,
diff56 = week6 - week5)
table(d$diff12)
table(d$diff23)
table(d$diff34)
table(d$diff45)
table(d$diff56)
# View(d[which(d$diff12 <9 | d$diff23 <9),])
d_counts <- list(
n12 = d %>% count(week1, week2),
n23 = d %>% count(week2, week3),
n34 = d %>% count(week3, week4),
n45 = d %>% count(week4, week5),
n56 = d %>% count(week5, week6)
)
d_counts$n12 = subset(d_counts$n12, !is.na(week1) & !is.na(week2))
d_counts$n23 = subset(d_counts$n23, !is.na(week2) & !is.na(week3))
d_counts$n34 = subset(d_counts$n34, !is.na(week3) & !is.na(week4))
d_counts$n45 = subset(d_counts$n45, !is.na(week4) & !is.na(week5))
d_counts$n56 = subset(d_counts$n56, !is.na(week5) & !is.na(week6))
# Heatmap
p <- ggplot(d_counts$n12, aes(x = week1, y = week2, fill = n)) +
geom_tile() +
scale_x_continuous(name = "First Participation",
limits = c(1,46),
breaks = seq(1,46, 3),
labels = seq(1,46, 3)) +
scale_y_continuous(name = "Second Participation",
limits = c(1,58),
breaks = seq(1,58, 3),
labels = seq(1,58, 3)) +
scale_fill_gradient(low = "white", high = "black") +
labs(x = "Week 1", y = "Week 2", fill = "Count") +
theme_minimal()
p
# d_counts$n12[which(d_counts$n12$n == max(d_counts$n12$n)), c("week1", "week2", "n")]
# d_counts$n12[which(d_counts$n12$n == min(d_counts$n12$n)), c("week1", "week2", "n")]
#
# d_counts$n23[which(d_counts$n23$n == max(d_counts$n23$n)), c("week2", "week3", "n")]
# d_counts$n23[which(d_counts$n23$n == min(d_counts$n23$n)), c("week2", "week3", "n")]
#
# d_counts$n34[which(d_counts$n34$n == max(d_counts$n34$n)), c("week3", "week4", "n")]
# d_counts$n34[which(d_counts$n34$n == min(d_counts$n34$n)), c("week4", "week4", "n")]
#
# d_counts$n45[which(d_counts$n45$n == max(d_counts$n45$n)), c("week4", "week5", "n")]
# d_counts$n45[which(d_counts$n45$n == min(d_counts$n45$n)), c("week4", "week5", "n")]
#
# d_counts$n56[which(d_counts$n56$n == max(d_counts$n56$n)), c("week5", "week6", "n")]
# d_counts$n56[which(d_counts$n56$n == min(d_counts$n56$n)), c("week6", "week6", "n")]
### combining week combinations
colnames(d_counts$n12) = colnames(d_counts$n23) = colnames(d_counts$n34) = colnames(d_counts$n45) = colnames(d_counts$n56) = c("w1", "w2", "n")
d_comb = bind_rows(d_counts$n12, d_counts$n23, d_counts$n34, d_counts$n45, d_counts$n56)
d_comb = d_comb %>% group_by(w1, w2) %>%
dplyr::summarise(n = sum(n))
d_comb[which(d_comb$n == max(d_comb$n)), c("w1", "w2", "n")]
d_comb[which(d_comb$n == min(d_comb$n)), c("w1", "w2", "n")]
# prop.table(table(dat$polpref_votepreslab3pt[dat$week == 11]))
d = read.xlsx("./extras/sikap_jeas.xlsx", sheet = 1)
d$source = factor(d$source,
levels = c("SIKAP (Week 11)",
"Indikator's January Survey",
"Indikator's Exit Poll",
"Official Result"))
d$candidate = factor(d$candidate,
levels = c("Anies Baswedan",
"Prabowo Subianto",
"Ganjar Pranowo"))
p <- ggplot(d, aes(x = candidate, y = vote, group = source)) +
geom_bar(aes(fill = source), stat = "identity", position = position_dodge(.9)) +
geom_text(aes(label = round(vote,2)), vjust = -0.2, size = 3, position = position_dodge(.9)) +
scale_x_discrete(name = "Candidate") +
scale_y_continuous(name = "Vote Share",
limits = c(0,62),
breaks = seq(0,100,10),
labels = seq(0,100,10)) +
theme_bw() +
scale_fill_manual(values = c("#d6d6d6", "#ababab", "#757575", "#454545")) +
labs(fill = NULL) +
theme(legend.position = "bottom")
p
ggsave(p, filename = "./output/figure_2.pdf", width = 7, height = 4)
ggsave(p, filename = "./output/figure_2.tiff", width = 7, height = 4, dpi = 300)
m = lm(polpref_jokowisatis2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df = ggeffect(m, terms = "weeklab")
df$predicted = df$predicted*100
df$conf.low = df$conf.low*100
df$conf.high = df$conf.high*100
p_approval <- ggplot(df, aes(x = x, y = predicted)) +
geom_line(group = 1) +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), group = 1, alpha = .1) +
scale_x_discrete(name = "Survey Week") +
scale_y_continuous(name = "Percent Respondents",
limits = c(50, 100),
breaks = seq(-15,100,5),
labels = seq(-15,100,5)) +
geom_hline(yintercept = 50) +
geom_vline(xintercept = 26, linetype = 4) +
geom_vline(xintercept = 27, linetype = 4) +
geom_label(aes(x = 25, y = 55), label = "MK's Ruling\nDPR's Defiance\nPublic Protests") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
labs(subtitle = "Satisfied or Very Satisfied with Jokowi's Performance")
p_approval
df
# ggsave("approval_trend.pdf", p_approval, width = 8, height = 6)
dat$feelpol_president_jokowi2pt = car::recode(dat$feelpol_president_jokowi,
"1:3 = 0;
4:5 = 1")
dat$feelpol_president_prabowo2pt = car::recode(dat$feelpol_president_prabowo,
"1:3 = 0;
4:5 = 1")
m_jokowi = lm(feelpol_president_jokowi2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df_jokowi = ggeffect(m_jokowi, terms = "weeklab")
df_jokowi$predicted = df_jokowi$predicted*100
df_jokowi$conf.low = df_jokowi$conf.low*100
df_jokowi$conf.high = df_jokowi$conf.high*100
df_jokowi$figure = "Jokowi"
m_prabowo = lm(feelpol_president_prabowo2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df_prabowo = ggeffect(m_prabowo, terms = "weeklab")
df_prabowo$predicted = df_prabowo$predicted*100
df_prabowo$conf.low = df_prabowo$conf.low*100
df_prabowo$conf.high = df_prabowo$conf.high*100
df_prabowo$figure = "Prabowo"
df = bind_rows(df_jokowi, df_prabowo)
p_fav <- ggplot(df, aes(x = x, y = predicted, group = figure)) +
geom_line(aes(linetype = figure)) +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high, group = figure), alpha = .1) +
scale_x_discrete(name = "Survey Week") +
scale_y_continuous(name = "Percent Respondents",
limits = c(40, 100),
breaks = seq(-15,100,5),
labels = seq(-15,100,5)) +
geom_hline(yintercept = 50) +
geom_vline(xintercept = 10, linetype = 4) +
geom_vline(xintercept = 11, linetype = 4) +
geom_label(aes(x = 8, y = 45), label = "MK's Ruling\nDPR's Defiance\nPublic Protests") +
geom_vline(xintercept = 19, linetype = 4) +
geom_vline(xintercept = 20, linetype = 4) +
geom_label(aes(x = 18, y = 45), label = "Prabowo\nInauguration") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
legend.position = c(.85, .15)) +
labs(subtitle = "Positive or Very Positive Feelings toward Jokowi and Prabowo",
linetype = "Figure")
p_fav
df
# ggsave("favorability_trend.pdf", p_fav, width = 8, height = 6)
dat$feelpol_president_jokowi2pt = car::recode(dat$feelpol_president_jokowi,
"1:3 = 0;
4:5 = 1")
dat$feelpol_president_prabowo2pt = car::recode(dat$feelpol_president_prabowo,
"1:3 = 0;
4:5 = 1")
m_jokowi = lm(feelpol_president_jokowi2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df_jokowi = ggeffect(m_jokowi, terms = "weeklab")
df_jokowi$predicted = df_jokowi$predicted*100
df_jokowi$conf.low = df_jokowi$conf.low*100
df_jokowi$conf.high = df_jokowi$conf.high*100
df_jokowi$figure = "Jokowi"
m_prabowo = lm(feelpol_president_prabowo2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df_prabowo = ggeffect(m_prabowo, terms = "weeklab")
df_prabowo$predicted = df_prabowo$predicted*100
df_prabowo$conf.low = df_prabowo$conf.low*100
df_prabowo$conf.high = df_prabowo$conf.high*100
df_prabowo$figure = "Prabowo"
df = bind_rows(df_jokowi, df_prabowo)
p_fav <- ggplot(df, aes(x = x, y = predicted, group = figure)) +
geom_line(aes(linetype = figure)) +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high, group = figure), alpha = .1) +
scale_x_discrete(name = "Survey Week") +
scale_y_continuous(name = "Percent Respondents",
limits = c(40, 100),
breaks = seq(-15,100,5),
labels = seq(-15,100,5)) +
geom_hline(yintercept = 50) +
geom_vline(xintercept = 10, linetype = 4) +
geom_vline(xintercept = 11, linetype = 4) +
geom_label(aes(x = 8, y = 45), label = "MK's Ruling\nDPR's Defiance\nPublic Protests") +
geom_vline(xintercept = 19, linetype = 4) +
geom_vline(xintercept = 20, linetype = 4) +
geom_label(aes(x = 18, y = 45), label = "Prabowo\nInauguration") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
legend.position = "bottom") +
labs(subtitle = "Positive or Very Positive Feelings toward Jokowi and Prabowo",
linetype = "Figure")
p_fav
df
# ggsave("favorability_trend.pdf", p_fav, width = 8, height = 6)
p <- p_approval + p_fav
ggsave(p, filename = "./output/figure_3.pdf", width = 12, height = 5)
ggsave(p, filename = "./output/figure_3.tiff", width = 12, height = 5, dpi = 300)
dat$feelpol_president_jokowi2pt = car::recode(dat$feelpol_president_jokowi,
"1:3 = 0;
4:5 = 1")
dat$feelpol_president_prabowo2pt = car::recode(dat$feelpol_president_prabowo,
"1:3 = 0;
4:5 = 1")
m_jokowi = lm(feelpol_president_jokowi2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df_jokowi = ggeffect(m_jokowi, terms = "weeklab")
df_jokowi$predicted = df_jokowi$predicted*100
df_jokowi$conf.low = df_jokowi$conf.low*100
df_jokowi$conf.high = df_jokowi$conf.high*100
df_jokowi$figure = "Jokowi"
m_prabowo = lm(feelpol_president_prabowo2pt  ~
femalefac + age_group + edulab3pt + religionlab3pt + region + javanese + weeklab,
data = dat)
df_prabowo = ggeffect(m_prabowo, terms = "weeklab")
df_prabowo$predicted = df_prabowo$predicted*100
df_prabowo$conf.low = df_prabowo$conf.low*100
df_prabowo$conf.high = df_prabowo$conf.high*100
df_prabowo$figure = "Prabowo"
df = bind_rows(df_jokowi, df_prabowo)
p_fav <- ggplot(df, aes(x = x, y = predicted, group = figure)) +
geom_line(aes(linetype = figure)) +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high, group = figure), alpha = .1) +
scale_x_discrete(name = "Survey Week") +
scale_y_continuous(name = "Percent Respondents",
limits = c(40, 100),
breaks = seq(-15,100,5),
labels = seq(-15,100,5)) +
geom_hline(yintercept = 50) +
geom_vline(xintercept = 10, linetype = 4) +
geom_vline(xintercept = 11, linetype = 4) +
geom_label(aes(x = 8, y = 45), label = "MK's Ruling\nDPR's Defiance\nPublic Protests") +
geom_vline(xintercept = 19, linetype = 4) +
geom_vline(xintercept = 20, linetype = 4) +
geom_label(aes(x = 18, y = 45), label = "Prabowo\nInauguration") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
legend.position = "bottom") +
labs(subtitle = "Positive or Very Positive Feelings toward Jokowi and Prabowo",
linetype = "")
p_fav
df
# ggsave("favorability_trend.pdf", p_fav, width = 8, height = 6)
p <- p_approval + p_fav
ggsave(p, filename = "./output/figure_3.pdf", width = 12, height = 5)
ggsave(p, filename = "./output/figure_3.tiff", width = 12, height = 5, dpi = 300)
