Rendered at 10:38 AM, Apr. 17, 2023
Ryan Thornburg (ryan.thornburg@unc.edu )
Article Tone by Incumbents vs. Challengers
Code
all_mentions %>%
select (2 : 5 , 1 , tenor_tone_of_article_re_candidate) %>%
filter (! is.na (tenor_tone_of_article_re_candidate)) %>%
#filter(tenor_tone_of_article_re_candidate %in% c("0","1","2")) %>%
group_by (tenor_tone_of_article_re_candidate, candidate_status) %>%
summarize (Articles= n ()) %>%
pivot_wider (names_from = "candidate_status" , values_from = Articles) %>%
adorn_percentages (denominator = 'col' ) %>%
adorn_pct_formatting () %>%
datatable (options = list (dom= 't' ),
colnames = c ('Tone' , 'Challengers' , 'Incumbents' ),
rownames = FALSE )
Article Tone for Each Candidate
For this, I re-coded invalid codes as “both positive and negative.” Devinney is not included in this table because the candidate received no article mentions.
Code
all_tone<- all_mentions %>%
select (2 : 5 , 1 , tenor_tone_of_article_re_candidate) %>%
mutate (tenor_tone_of_article_re_candidate =
case_when (
str_detect (tenor_tone_of_article_re_candidate,"0; 1; 2" ) ~ "3" ,
str_detect (tenor_tone_of_article_re_candidate,"3" ) ~ "3" ,
str_detect (tenor_tone_of_article_re_candidate,"1" ) ~ "1" ,
str_detect (tenor_tone_of_article_re_candidate,"2" ) ~ "2" ,
str_detect (tenor_tone_of_article_re_candidate,"0" ) ~ "0"
)) %>%
filter (! is.na (tenor_tone_of_article_re_candidate)) %>%
group_by (state, contest, candidate_name, candidate_status,
tenor_tone_of_article_re_candidate) %>%
summarize (Articles = n ()) %>%
pivot_wider (names_from = tenor_tone_of_article_re_candidate,
names_prefix = "code_" ,
names_sort = TRUE ,
values_from = Articles) %>%
mutate_if (is.numeric, replace_na, 0 )
all_tone %>%
datatable (
colnames = c ('State' , 'Contest' , 'Canddiate' , 'Status' , 'Neutral Articles' , 'Mostly Positive' , 'Mostly Negative' , 'Both' ),
rownames = FALSE )
Candidates who received the most negative coverage.
Code
all_tone %>%
left_join (competitiveness, b = c ("state" , "contest" )) %>%
select (3 : 4 ,type,contains ("code" ), 1 : 2 ) %>%
adorn_percentages (denominator = 'row' ) %>%
filter (code_2 > .05 ) %>%
arrange (desc (code_2) ) %>%
adorn_pct_formatting () %>%
datatable (list (pageLength = 16 ),
colnames = c ('Candidate' , 'Cand. Status' , 'Compete Type' , 'Neutral Articles' , 'Mostly Positive' , 'Mostly Negative' , 'Both' , 'State' , 'Contest' ),
rownames = FALSE )