--- title: "figures" format: pdf editor: visual execute: echo: false warning: false --- ```{r} library(ggplot2) library(dplyr) library(tidyr) sysfonts::font_add_google("EB Garamond") theme_set(theme_minimal(base_family = "EB Garamond")) theme_update(text = element_text(size = 50)) library(showtext) showtext_auto() data = read.csv("../full_data.csv") #rubriques_lemonde = c("international","culture","politique","société","économie","sport","science/technologie","inclassable") #z = data$rubrique %in% rubriques_lemonde #data$rubrique[!z] = "inclassable" data$sexe_prenom = data$sexe_prenom %>% recode(Femme = "Women",Homme = "Men") data$rubrique[data$rubrique=="Science/tech"] = "Culture" data$rubrique = data$rubrique %>% recode(économie = "Economics",politique = "Politics",société = 'Society',"science/technologie" = "Science/tech",culture="Culture",international = "International",sport="Sport",inclassable = "Unclassifiable") ``` ```{r} #| fig-cap: Masculinity rate of mentions and quotes in the whole corpus d = data%>% group_by(year) %>% summarise( citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women,na.rm=T), mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women,na.rm=T), nwords = sum(nwords) #entities = sum(entities) ) d$mentions_total = d$mentions_men + d$mentions_women fig = ggplot(d %>% filter(mentions_women > 20),aes(year,mentions_men/(mentions_men+mentions_women),linetype="Mentions")) + geom_line() + geom_line(aes(year,citations_men/(citations_men+citations_women),linetype="Quotes")) + #scale_linetype_manual(values = c("Mentions" = "solid", "Quotes" = "dotted")) + ylab("Masculinity rate") + xlab("Date") + labs(linetype="Measure") + ylim(.5, 1) ggsave("../figures/fig1.png",fig,dpi=320,bg="white",width=7, height=5) ``` ```{r} #| fig-cap: Masculinity rate of mentions per news section, excluding unclassifiable d = data %>% filter(!rubrique %in% c("Unclassifiable")) %>% group_by(year,rubrique) %>% summarise( citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women,na.rm=T), mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women,na.rm=T), signatures_men = sum(sexe_prenom=="Men"), signatures_women= sum(sexe_prenom=="Women") ) d$mentions_total = d$mentions_men + d$mentions_women ggplot(d %>% filter(mentions_women > 20,year > 1944),aes(year,mentions_men/(mentions_men+mentions_women),linetype="Mentions")) + geom_line() + geom_line(aes(year,citations_men/(citations_men+citations_women),linetype="Quotes")) + #geom_line(data = filter(d,!year %in% missing_years),aes(year,signatures_men/(signatures_men+signatures_women),linetype="Signatures")) + # scale_linetype_manual(values = c("Mentions" = "solid", "Quotes" = "dotted")) + ylab("Masculinity rate") + xlab("Date") + labs(linetype="Measure") + ylim(c(.5,1)) + facet_wrap(.~rubrique,nrow = 2,ncol=3) + theme( strip.text = element_text(size = 40, family = "EB Garamond"), axis.text.x = element_text(size = 30) ) ggsave("../figures/masc_mentions_sections.png",dpi=320,bg="white",width=7, height=5) ``` ```{r} #| fig-cap: Masculinity rates of mentions and quotes, depending on the journalist gender. We ignore the points where there are less than 100 mentions or citations, and the 1987-1994 and 2003-2004, where the author metadata is mostly missing due to errors of digitization. #| fig-width: 9.5 library(cowplot) missing_years = c(1987:1994,2003:2004) d = filter(data,sexe_prenom %in% c("Women","Men")) d = d %>% group_by(year,sexe_prenom) %>% summarise( mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women,na.rm=T), citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women,na.rm=T) ) d$mentions_total = d$mentions_men + d$mentions_women d$citations_total = d$citations_men + d$citations_women # Create the plots a <- ggplot(d %>% filter(mentions_total > 100, !year %in% missing_years), aes(year, mentions_men/mentions_total, shape = sexe_prenom)) + geom_point() + ylab("Mentions masculinity rate") + labs(shape = "Journalist gender") + xlab("Date") + scale_shape_manual(values = c("Women" = 2, "Men" = 16)) b <- ggplot(d %>% filter(citations_total > 100, !year %in% missing_years), aes(year, citations_men/citations_total, shape = sexe_prenom)) + geom_point() + ylab("Quotes masculinity rate") + labs(shape = "Journalist gender") + xlab("Date") + scale_shape_manual(values = c("Women" = 2, "Men" = 16)) # Create the legend separately legend <- get_legend(a) # Combine the plots and legend plots <- plot_grid(a + theme(legend.position = "none"), b + theme(legend.position = "none"), nrow=2,rel_heights = c(.5,.5)) fig <- plot_grid(plots, legend, ncol = 2, rel_widths = c(1, 0.15)) d$mmr = d$mentions_men/d$mentions_total z = d$mentions_total < 100 d$mmr[z] = NA d$qmr = d$citations_men/d$citations_total z = d$citations_total < 100 d$qmr[z] = NA dd = gather(d %>% select("year","sexe_prenom","qmr","mmr"),"key","value",-year,-sexe_prenom) dd$key = dd$key %>% recode(mmr = "Mentions",qmr = "Quotes") ggplot(dd %>% filter(!year %in% missing_years), aes(year, value, shape = sexe_prenom)) + geom_point() + ylab("Masculinity rate") + labs(shape = "Journalist gender") + xlab("Date") + scale_shape_manual(values = c("Women" = 2, "Men" = 16)) + facet_wrap(.~key,nrow = 2) ggsave("../figures/measures_journalist_gender.png", dpi=320, bg="white", width=7, height=5) ``` ```{r} #| fig-cap: Masculinity rates of mentions, depending on the journalist gender, by news section (omitting sports and unclassifiable articles). library(dplyr) d = filter(data,sexe_prenom %in% c("Women","Men"),!rubrique %in% c("Unclassifiable")) d = d %>% group_by(year,sexe_prenom,rubrique) %>% summarise( mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women,na.rm=T), citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women,na.rm=T) ) d$mentions_total = d$mentions_men + d$mentions_women d$citations_total = d$citations_men + d$citations_women ggplot(d %>% filter(citations_women > 10),aes(year,citations_women/citations_total,shape=sexe_prenom)) + geom_point() + geom_smooth(se=F) + ylab("Masculinity rate of quotes") + facet_wrap(.~rubrique,scales="free_y") + labs(shape="Journalist gender") + theme( strip.text = element_text(size = 10, family = "EB Garamond"), axis.text.x = element_text(size = 7)) + xlab("Date") + scale_shape_manual(values = c("Women" = 2, "Men" = 16)) ggsave("../figures/measures_journalist_gender_sections.png", dpi=320, bg="white", width=7, height=5) ``` ```{r} #| fig-cap: Masculinity rates of mentions, depending on the journalist gender, by news section (omitting unclassifiable articles). ggplot(d %>% filter(mentions_women > 100),aes(year,mentions_women/mentions_total,shape=sexe_prenom)) + geom_point() + ylab("Masculinity rate of mentions") + facet_wrap(.~rubrique,scales="free_y") + labs(shape="Journalist gender") + theme( strip.text = element_text(size = 10, family = "EB Garamond"), axis.text.x = element_text(size = 7) ) + scale_shape_manual(values = c("Women" = 2, "Men" = 16)) + xlab("Date") ggsave("../figures/mentions_journalist_gender_sections.png", dpi=320, bg="white", width=7, height=5) ``` ```{r} #| fig-cap: Difference between mentions and citations of women, between women and men journalists. This Figure aims at capturing the to what extent women journalists mention and quote more women, over time. d = filter(data,sexe_prenom %in% c("Women","Men"),!year %in% missing_years) %>% group_by(year,sexe_prenom) %>% summarise( mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women,na.rm=T), citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women,na.rm=T) ) d$mentions_total = d$mentions_men + d$mentions_women d$citations_total = d$citations_men + d$citations_women d$feminity_mentions = d$mentions_women/d$mentions_total d$feminity_citations = d$citations_women/d$citations_total d_bis = d %>% filter(citations_total > 100) %>% select(year,sexe_prenom,feminity_mentions,feminity_citations) %>% pivot_wider(names_from = sexe_prenom, values_from = c(feminity_mentions,feminity_citations), id_cols = c( year)) ggplot(d_bis,aes(year,feminity_citations_Women-feminity_citations_Men,color="Citations")) + geom_point() + geom_smooth(se=F) + geom_point(aes(year,feminity_mentions_Women-feminity_mentions_Men,color="Mentions")) + geom_smooth(aes(year,feminity_mentions_Women-feminity_mentions_Men,color="Mentions"),se=F) + ylab("Gap between women and men journalists") + labs(color="Measure") + xlab("Date") ``` ```{r} d = filter(data,sexe_prenom %in% c("Women","Men")) d = d %>% group_by(year,sexe_prenom) %>% summarise( n = n() ) d[d$year %in% missing_years,"n"] = NA d_bis = d %>% pivot_wider(names_from = sexe_prenom, values_from = n) d_bis$feminity = d_bis$Men/(d_bis$Women+d_bis$Men) ggplot(d_bis,aes(year,feminity)) + geom_line(na.rm=T) + ylab("Masculinity of articles signatures") + labs(color="Journalist gender") +xlab("Date") ggsave("../figures/signatures.png",dpi=320,bg="white",width=7, height=5) ``` ```{r} d = filter(data,sexe_prenom %in% c("Women","Men"), rubrique != "Unclassifiable") d = d %>% group_by(year,sexe_prenom,rubrique) %>% summarise( n = n() ) d[d$year %in% missing_years,"n"] = NA d_bis = d %>% pivot_wider(names_from = sexe_prenom, values_from = n) d_bis = d_bis %>% mutate(Women = replace_na(Women, 0)) d_bis$feminity = d_bis$Men/(d_bis$Women+d_bis$Men) ggplot(d_bis,aes(year,feminity)) + geom_line(na.rm=T) + ylab("Masculinity of articles signatures") + labs(color="Journalist gender") +xlab("Date") + facet_wrap(.~rubrique) ggsave("../figures/signatures_rubriques.png",dpi=320,bg="white",width=7, height=5) ``` ```{r} z = data %>% group_by(year) %>% summarise(nwords = sum(nwords)) ggplot(z,aes(year,nwords)) + geom_area(stat = 'identity') + xlab("Date") + ylab("Words per year") ggsave("../figures/nwords.png",dpi=320,bg="white",width=7, height=5) ``` ```{r} z = data %>% filter(!rubrique %in% c("Unclassifiable","Science/tech")) %>% group_by(year,rubrique) %>% summarise(nwords = sum(nwords)) z = z %>% group_by(year) %>% mutate(total_nwords_per_year = sum(nwords), normalized_nwords = nwords / total_nwords_per_year) %>% ungroup() ggplot(z,aes(year,normalized_nwords)) + geom_area(stat = 'identity') + xlab("Date") + ylab("Words per year in the corpus") + facet_wrap(.~rubrique, ncol = 3, nrow = 2) ggsave("../figures/nwords_rubrique.png",dpi=320,bg="white",width=7, height=5) ``` ```{r} library(glue) library(tidyr) mean_male = vector() mean_female = vector() for(i in 1945:2022){ a = read.csv(glue("~/Downloads/verbs_nonagg/quotes_verbs_{i}.csv"),sep = "\t") mean_male = c(mean_male,mean(a[a$speaker_gender=="Male",]$n_tok)) mean_female = c(mean_female,mean(a[a$speaker_gender=="Female",]$n_tok)) } result = data.frame(year = 1945:2022,Male = mean_male,Female = mean_female) result_gather = gather(result,"Gender","value",-year) ggplot(result_gather,aes(year)) + geom_ribbon(data = result, aes(ymin = pmin(Male, Female), ymax = pmax(Male, Female), fill = Male > Female, group = cumsum(c(0, diff(Male > Female) != 0))), alpha = .3,show.legend = FALSE) + geom_line(aes(y=value,linetype=Gender)) + xlab("Date") + ylab("Mean quote length (words)")+ scale_fill_manual(values = c("TRUE" = "lightblue", "FALSE" = "pink"), labels = c("TRUE" = "Male > Female", "FALSE" = "Female > Male"), name = "Difference") ggsave("../figures/length_quotes.png",dpi=320,bg="white",width=7, height=5) ggplot(result, aes(year,Male/Female)) + geom_point() + geom_smooth(color="black",se=F) ``` ```{r} #Stereotypes data preparation #files = read.csv("~/Downloads/citations_by_article.csv", # col.names = c("filename","n_men","n_women","verbs_men", # "verbs_men_lemmatized","verbs_women","verbs_women_lemmatized")) #z = duplicated(files$filename) #files = files[!z,] #library(stringr) #files$filename = str_c(files$filename,".txt") #z = duplicated(data$filename) #verbs_data = data[!z,c("filename","sexe_prenom","year","rubrique")] %>% # right_join(files,by="filename") #verbs_data = filter(verbs_data,sexe_prenom =="Men") verbs = unique(read.csv("https://raw.githubusercontent.com/gillesbastin/old_fashion_nlp/refs/heads/main/cues_all.csv")$lemmatized_cue) ``` ```{r} ##Compute odds ratios verbs = unique(read.csv("https://raw.githubusercontent.com/gillesbastin/old_fashion_nlp/refs/heads/main/cues_all.csv")$lemmatized_cue) threshold = 30 men = data %>% group_by(year) %>% mutate( verbs_men_lemmatized = strsplit(verbs_men_lemmatized, ";")) %>% unnest(verbs_men_lemmatized) %>% count(verbs_men_lemmatized) %>% ungroup() %>% complete(verbs_men_lemmatized = verbs,fill = list(n = 0,year = 1945)) %>% arrange(verbs_men_lemmatized) z = is.na(men$verbs_men_lemmatized) men <- men[!z,] %>% pivot_wider( names_from = verbs_men_lemmatized, values_from = n, values_fill = 0 ) men = dplyr::filter(men,year %in% 1945:2024) men$decade = (men$year-1945) %/% 10 men = men %>% dplyr::select(-year) %>% group_by(decade) %>% summarise(across(everything(),sum)) women = data %>% group_by(year) %>% mutate( verbs_women_lemmatized = strsplit(verbs_women_lemmatized, ";")) %>% unnest(verbs_women_lemmatized) %>% count(verbs_women_lemmatized) %>% ungroup() %>% complete(verbs_women_lemmatized = verbs,fill = list(n = 0,year = 1945)) %>% arrange(verbs_women_lemmatized) z = is.na(men$verbs_men_lemmatized) women <- women[z,] %>% pivot_wider( names_from = verbs_women_lemmatized, values_from = n, values_fill = 0 ) women = dplyr::filter(women,year %in% 1945:2024) women$decade = (women$year-1945) %/% 10 women = women %>% dplyr::select(-year) %>% group_by(decade) %>% summarise(across(everything(),sum)) total_men = rowSums(men) total_women = rowSums(women) odds_ratios = (men/total_men)/(women/total_women) log_odds_ratios = odds_ratios %>% log2() log_odds_ratios = data.frame(log_odds_ratios) log_odds_ratios[log_odds_ratios == Inf | log_odds_ratios == -Inf] <- NA vars = 1/men + 1/women #log_odds_ratios[vars > .025] = NA log_odds_ratios[men+women < threshold] = NA vars[men+women < threshold] = NA #vars[vars > .01] = NA ``` ```{r} ##Plot degree of stereotype v = is.na(log_odds_ratios[1,]) #stereotypes = apply(log_odds_ratios[,!v], 1, function(x) 1/sum(!is.na(x))*sum(x^2, na.rm = TRUE)) stereotypes = apply(log_odds_ratios[,!v], 1, function(x) sd(x,na.rm = TRUE)) years <- 1940 + (1:8) * 10 stereotypes_df <- data.frame( Year = years, stereotypes = stereotypes ) plot1 = ggplot(stereotypes_df, aes(x = Year, y = stereotypes)) + geom_line() + ylab("Standard deviation among verbs") + scale_x_continuous(breaks = years) + xlab("Date") z = log_odds_ratios z[men + women < 100] = NA v = is.na(z[1,]) z = z[,!v] z$decade = 1940 + (1:8)*10 z = gather(z,"key","value",-decade) total = colSums(men[,!as.vector(v)] + women[,!as.vector(v)],na.rm=T) %>% data.frame() total$key = row.names(total) z = left_join(z,total,by="key") z = filter(z,!key %in% excl) colnames(z)[4] = "s" plot2 = ggplot(z,aes(decade,value,group=key)) + geom_line(aes(alpha =log(s)),linewidth=.4) + scale_alpha_continuous(guide = "none") + scale_x_continuous(breaks = years) + ylab("Verbs log odd-ratio") + xlab("") plot_grid(plot2,plot1,nrow=2,labels = c("A","B"),align="v",label_size = 50,label_x = .1) ggsave("../figures/spaghetti.png",dpi=320,bg="white",width=9, height=7) #ggsave("../figures/stereoptype_over_time.png",dpi=320,bg="white",width=7, height=5) ``` ```{r} stereotypes_verbs = colMeans(log_odds_ratios/(stereotypes/mean(stereotypes)),na.rm=T) stereotypes_verbs[colSums(men) + colSums(women) < 100] = NA stereotypes_verbs = stereotypes_verbs %>% data.frame() colnames(stereotypes_verbs) = "Masculinity" stereotypes_verbs$var = colMeans(vars,na.rm=T)/colSums(!is.na(vars)) stereotypes_verbs$Verb = colnames(men) stereotypes_verbs = stereotypes_verbs %>% filter(!is.na(Masculinity)) %>% arrange(Masculinity) excl = c("naître","falloir","aimer","consacrer","savoir","demeurer","sembler","rester","mettre","devenir","devoir","diriger","créer","convier","connaître","attendre","aller",'organiser') stereotypes_verbs = filter(stereotypes_verbs,!Verb %in% excl) n = 20 gaps <- data.frame( Masculinity = rep(0, 3), # No bar for the gap var = rep(0, 3), # No error bar for the gap Verb = c("...", "...", "...") # Multiple placeholders, ) verbs_plot_with_gap = rbind(head(stereotypes_verbs,15),gaps,tail(stereotypes_verbs,15)) verbs_plot_with_gap$Verb_english = dplyr::recode(verbs_plot_with_gap$Verb,murmurer="Whisper",raconter="Recount",sourire="Smile",hurler="Scream",traduire="Translate",souvenir="Remember",soupirer="Sigh",témoigner='Testify',lire='Read',avouer='Avow','(s)enthousiasmer'='Enthuse',relater='Relate',réaliser="Realize",enchaîner="Continue",finir="End",estimer='Estimate',avertir='Warn',reprocher="Reproach",accuser="Accuse",calculer ="Calculate",arguer="Argue",indiquer="Indicate",menacer="Threaten",ajouter='Add',inviter="Invite",mentionner='Mention',tonner="Thunder",déclarer="Declare",promettre="Promise",prédire="Predict",'(se)désoler'='Lament',glisser='Slip', railler="Mock",exprimer="Express") verbs_plot_with_gap$Verb = dplyr::recode(verbs_plot_with_gap$Verb,souvenir="(se)souvenir") breaks <- c(log2(0.25), log2(0.5), 0, log2(2), log2(4), log2(8)) labels <- c("0.25x", "0.5x", "Same", "2x", "4x", "8x") ggplot(verbs_plot_with_gap, aes(x = -Masculinity, y = reorder(Verb, -Masculinity))) + geom_bar(stat = "identity", fill = "black", alpha = 0.4, width = 0.3) + geom_errorbar(aes( xmin = -Masculinity - sqrt(var), xmax = -Masculinity + sqrt(var) ), width = 0.2) + geom_vline(xintercept = 0, linetype = "dashed", color = "gray50") + ylab("Verb") + theme( panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank(), ) + scale_x_continuous( breaks = breaks, labels = labels,limits=c(NA,2.4) ) + xlab("Relative appearance for women vs men") + geom_text(aes(x=2.2,y = reorder(Verb, -Masculinity),label=tolower(Verb_english)),hjust=0,family = 'EB Garamond',size=14,alpha=.7) ggsave("../figures/most_gendered_verbs.png",dpi=320,bg="white",width=9, height=5) ``` ```{r} ##Segregation mentions dd = data%>% filter(mentions_women > .995,rubrique!= "Uncl assifiable",year > 1945) %>% group_by(year,rubrique) %>% summarise(##Measuring sex-ratio experienced by women citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women-1,na.rm=T), mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women-.995,na.rm=T), nwords = sum(nwords) #entities = sum(entities) ) d = data %>% filter(year > 1945,rubrique!= "Unclassifiable") %>% group_by(year,rubrique) %>% summarise(##General sex ratio citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women,na.rm=T), mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women,na.rm=T), nwords = sum(nwords) #entities = sum(entities) ) dd$women_ratio = dd$mentions_women/(dd$mentions_men+dd$mentions_women) d$women_ratio = d$mentions_women/(d$mentions_men+d$mentions_women) dd = dd %>% merge(d,by = c("year","rubrique")) dd$exposure_index = dd$women_ratio.x/dd$women_ratio.y ggplot(filter(dd,mentions_women.y > 100),aes(year,exposure_index)) + geom_line() + facet_wrap(.~rubrique) + xlab("Date") + ylab("Women overexposure to women mentions") + scale_y_continuous(trans="log2") ggsave("../figures/segregation_mentions.png",dpi=320,bg="white",width=9, height=5) ``` ```{r} dd = data%>% filter(citations_women > .995,rubrique!= "Unclassifiable",year > 1945) %>% group_by(year,rubrique) %>% summarise( citations_men = sum(citations_men,na.rm=T), citations_women = sum(citations_women-1,na.rm=T), mentions_men = sum(mentions_men,na.rm=T), mentions_women = sum(mentions_women-.995,na.rm=T), nwords = sum(nwords) #entities = sum(entities) ) dd$women_ratio = dd$citations_women/(dd$citations_men+dd$citations_women) d$women_ratio = d$citations_women/(d$citations_men+d$citations_women) dd = dd %>% merge(d,by = c("year","rubrique")) dd$exposure_index = dd$women_ratio.x/dd$women_ratio.y ggplot(filter(dd,citations_women.y > 100),aes(year,exposure_index)) + geom_line() + ylim(c(.8,NA)) + facet_wrap(.~rubrique) + xlab("Date") + ylab("Women overexposure to women citations") + scale_y_continuous(trans="log2") ggsave("../figures/segregation_citations.png",dpi=320,bg="white",width=9, height=5) ``` ```{r} #quotes length data preparation files = read.csv("~/Downloads/citations_length_by_article.csv", col.names = c("filename","n_men","n_women","length_men", "length_women")) z = duplicated(files$filename) files = files[!z,] library(stringr) files$filename = str_c(files$filename,".txt") z = duplicated(data$filename) length_data = data[!z,c("filename","sexe_prenom","year","rubrique")] %>% right_join(files,by="filename") z = length_data %>% group_by(year) %>% mutate( length_men = strsplit(length_men, ";") %>% lapply(as.integer), length_women = strsplit(length_women, ";") %>% lapply(as.integer)) z_men = z %>% unnest(length_men)%>% group_by(year) %>% summarise(mean_quote_length=mean(length_men)) z_women = z %>% unnest(length_women) %>% group_by(year) %>% summarise(mean_quote_length=mean(length_women)) z_men$ratio_length = z_men$mean_quote_length/z_women$mean_quote_length ggplot(z_men %>% filter(year > 1944),aes(year,ratio_length)) + geom_point() + geom_smooth(color='black',se=F) + xlab("Date") + ylab("Male-to-female quote length ratio") ggsave("../figures/length.png",dpi=320,bg="white",width=9, height=5) ```