This study examines four hundred and fifty four commemorative articles about assasinated Nigerian journalist, Dele Giwa, to identify the dominant themes. The study also analyzes differences in the commemoration during the military era (1987 to May 1999) and civilian (1999 to 2023).
The 454 articles were loaded into R, cleaned and prepared for analysis. The unit of analysis are articles about Dele Giwa. The following analysis were run with the ultimate aim of identifying dominant themes: Bigrams: The dataset was tokenized and then analyzed for bigrams to reveal the top phrases. Topic modelling: Latent Dirichlet Allocation (LDA) was used to cluster words into topics. This will also be used to examine how the themes evolve over time (military vs. civilian era). Sentiment analysis: The Afinn dictionary will be used to analyze the overall tone of the articles. (Not sure about this yet because I think this won’t bring anything special)
Below is a coding scheme developed based on the literature and my familiarization with the data: Bravery and Sacrifice: Mentions of Dele Giwa’s courage, investigative prowess, or ultimate sacrifice for truth and justice. Calls for Justice: different expressions advocating for justice or accountability for his assassination. Criticism of Authorities: Critical reflections on the failure of successive governments, law enforcement, or judiciary to solve the murder will fall under this category Freedom of the Press: Themes highlighting press freedom and the risks journalists face in Nigeria. Comparison of Eras: Contrasts between the military and civilian eras in terms of press freedom, accountability, or socio-political environment. Role Model: Description of Dele Giwa as an icon of good journalism whose work inspires other journalists.
library(pdftools)
## Using poppler version 23.08.0
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(stringr)
library(readxl)
library(rio)
library(tidytext)
library(dplyr)
library(tidyr)
#link - https://github.com/kemibus/kemi_new/blob/main/dele.PDF
# Specify the file path
#filepath <- "~/GitHub/kemi_new/dele.PDF"
#Read pdf and coverting it into text
text <- pdf_text("~/GitHub/kemi_new/dele.PDF")
#write to a text file
writeLines (text, "~/GitHub/kemi_new/dele.text")
#Read the text from the PDF
#dele_text <- pdf_text("~/GitHub/kemi_new/dele.PDF")
file_path <- ("~/GitHub/kemi_new/dele.text")
text_data <- read_lines(file_path)
# Combine all the pages into one text
text_combined <- paste(text_data, collapse = "\n")
# Split the text by the "End of Document" phrase
dele_split <- strsplit(text_combined, "End of Document")[[1]]
# Set the output directory for saving the split files
output_dir <- "~/GitHub/kemi_new/dele_extracted"
# Write each section to a new text file
for (i in seq_along(dele_split)) {
output_file <- file.path(output_dir, paste0("dele_extracted", i, ".txt"))
writeLines(dele_split[[i]], output_file)
}
# Print a message to confirm how many files were created
cat("Files created:", length(dele_split), "\n")
## Files created: 455
dele_index <- read_lines("~/GitHub/kemi_new/dele_extracted/dele_extracted1.txt")
extracted_lines <-dele_index[16:1504]
cat(head(extracted_lines, 7), sep = "\n")
##
## 1. Remembering Dele Giwa
##
##
## 2. Dele Giwa's Death: 37yrs After, Council Chairman Establishes Essay Competition
extracted_lines <- extracted_lines |>
as.data.frame()
# Step 1: Trim spaces and detect rows with titles and dates
cleaned_data <- extracted_lines |>
mutate(
# Trim leading and trailing spaces before detection
trimmed_line = str_trim(extracted_lines),
# Detect titles (start with a number and a period)
is_title = str_detect(trimmed_line, "^\\d+\\. "),
# Detect dates (e.g., "Aug 14, 2024")
is_date = str_detect(trimmed_line, "\\b\\w{3} \\d{1,2}, \\d{4}\\b")
)
# Step 2: Shift dates to align with corresponding titles
aligned_data <- cleaned_data |>
mutate(
date = ifelse(lead(is_date, 1), lead(trimmed_line, 1), NA_character_) # Shift date to title's row
) |>
filter(is_title) |>
select(trimmed_line, date) # Keep only the relevant columns
# Step 3: Rename columns for clarity
final_data <- aligned_data |>
rename(
title = trimmed_line,
date = date
)
# Step 4: Date and Publication in separate columns, and formatted
final_data <- separate(data = final_data, col = date, into = c("date2", "publication"), sep = " ", extra = "merge", fill = "right")
# Step 5: Format date, clean headline
final_data <- final_data |>
mutate(date = as.Date(date2,format = "%b %d, %Y")) |>
mutate(title = str_remove(title, "^\\d+\\. ")) |>
subset(select = -(date2)) |>
mutate(index = row_number()) |>
select(index, date, title, publication)
# Save final data
write_csv(final_data, "./final_data.csv")
# List all text files in the directory
files <- list.files("~/GitHub/kemi_new/dele_extracted", pattern="*.txt") |>
as.data.frame() |>
rename(filename = 1) |>
mutate(
# Create an index with the file name
index = str_extract(filename, "\\d+"),
index = as.numeric(index)
)
# Join the file list to the final_data dataframe based on index
final_index <- final_data |>
inner_join(files, c("index")) |>
mutate(filepath = paste0("~/GitHub/kemi_new/dele_extracted/", filename))
# Display the head of the compiled dataframe with filenames and content
head(final_index)
## index date
## 1 1 <NA>
## 2 2 <NA>
## 3 3 <NA>
## 4 4 <NA>
## 5 5 <NA>
## 6 6 <NA>
## title
## 1 Remembering Dele Giwa
## 2 Dele Giwa's Death: 37yrs After, Council Chairman Establishes Essay Competition
## 3 Letter bomb did not kill Dele Giwa — Saka
## 4 AFRICMIL invites young journalists to submit essays on late Dele Giwa
## 5 37 years after Giwa's death: Etsako council chairman set up secondary school essay
## 6 Utomi, Falana to attend lecture in honour of #EndSARS, Dele Giwa
## publication filename
## 1 <NA> dele_extracted1.txt
## 2 <NA> dele_extracted2.txt
## 3 <NA> dele_extracted3.txt
## 4 <NA> dele_extracted4.txt
## 5 <NA> dele_extracted5.txt
## 6 <NA> dele_extracted6.txt
## filepath
## 1 ~/GitHub/kemi_new/dele_extracted/dele_extracted1.txt
## 2 ~/GitHub/kemi_new/dele_extracted/dele_extracted2.txt
## 3 ~/GitHub/kemi_new/dele_extracted/dele_extracted3.txt
## 4 ~/GitHub/kemi_new/dele_extracted/dele_extracted4.txt
## 5 ~/GitHub/kemi_new/dele_extracted/dele_extracted5.txt
## 6 ~/GitHub/kemi_new/dele_extracted/dele_extracted6.txt
## Joining with `by = join_by(filename)`
# Load necessary libraries
library(dplyr)
library(tidytext)
library(stringr)
bigrams <- articles_df %>%
select(sentence) %>%
mutate(
sentence = str_squish(sentence),
sentence = tolower(sentence),
sentence = str_replace_all(sentence, c(
"copyright" = "",
"new york times"="",
"publication"="",
"www.alt"="",
"http"=""))) %>%
unnest_tokens(bigram, sentence, token = "ngrams", n = 2) %>%
separate(bigram, c("word1", "word2"), sep = " ") %>%
filter(!word1 %in% stop_words$word) %>% # Filter out stop words
filter(!word2 %in% stop_words$word) %>%
count(word1, word2, sort = TRUE) %>%
filter(!is.na(word1) & !is.na(word2))
# Ensure `stop_words` data is available
data("stop_words")
# Define the expanded remove pattern for unwanted terms
remove_pattern <- paste(
"title", "pages", "publication date", "publication subject", "publication type",
"issn", "language of publication: english", "document url", "copyright", "news", "lenght", "words", "load", "date", "live updates", "updates assembly", "polling", "units", "total votes",
"service last updated", "database", "start of article", "rights reserved",
"local assembly", "local government", "ups assembly", "live ups", "elections",
"accredited voters", "governorship", "registered", "total", "votes", "cast",
"valid", "rejected", "polling units", "electoral commission",
"progressives congress", "independent", "inec", "presidential", "proquest document id",
"classification", "illustration", "caption", "[0-9.]+", "_ftn", "[_]+", "aaa",
"jcr:fec", "___________________", "rauchway", "keynes's", "language", "english",
"length words", sep = "|"
)
# Process bigrams
bigrams <- articles_df %>%
select(sentence) %>%
mutate(
sentence = str_squish(sentence), # Remove extra spaces
sentence = tolower(sentence), # Convert to lowercase
sentence = str_replace_all(sentence, remove_pattern, ""), # Remove unwanted terms
sentence = str_replace_all(sentence, "- ", ""), # Remove trailing hyphens
sentence = str_replace_all(sentence, "\\b[a-zA-Z]\\b", "") # Remove single characters
) %>%
unnest_tokens(bigram, sentence, token = "ngrams", n = 2) %>%
separate(bigram, c("word1", "word2"), sep = " ") %>%
filter(!word1 %in% stop_words$word) %>% # Filter out stop words
filter(!word2 %in% stop_words$word) %>%
filter(!word1 %in% remove_pattern) %>%
count(word1, word2, sort = TRUE) %>%
filter(!is.na(word1) & !is.na(word2)) # Filter out NAs
bigrams
## # A tibble: 56,656 × 3
## word1 word2 n
## <chr> <chr> <int>
## 1 dele giwa 1089
## 2 human rights 184
## 3 ray ekpu 176
## 4 global media 165
## 5 parcel bomb 154
## 6 allafrica global 150
## 7 syndigate media 147
## 8 letter bomb 141
## 9 daily times 138
## 10 ibrahim babangida 130
## # ℹ 56,646 more rows
top_bigrams <- bigrams %>%
arrange(desc(n)) %>%
head(20)
print(top_bigrams)
## # A tibble: 20 × 3
## word1 word2 n
## <chr> <chr> <int>
## 1 dele giwa 1089
## 2 human rights 184
## 3 ray ekpu 176
## 4 global media 165
## 5 parcel bomb 154
## 6 allafrica global 150
## 7 syndigate media 147
## 8 letter bomb 141
## 9 daily times 138
## 10 ibrahim babangida 130
## 11 watch magazine 130
## 12 boko haram 128
## 13 democratic party 125
## 14 national assembly 118
## 15 journalist dele 111
## 16 giwa death 108
## 17 security agencies 107
## 18 olusegun obasanjo 103
## 19 federal government 95
## 20 mass communication 94
# Ensure the required libraries are loaded
ggplot(top_bigrams, aes(x = reorder(paste(word1, word2, sep = " "), n), y = n)) +
geom_col(fill = "steelblue") +
coord_flip() +
labs(
title = "Top bigrams from articles",
caption = "n=454 articles. Graphics by Kemi Busari. Dec 1, 2024",
x = "Phrases",
y = "Count of phrases"
) +
theme_minimal(base_size = 14) +
theme(
plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
plot.caption = element_text(hjust = 0, face = "italic", size = 10),
axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold")
)
nrow(final_data)
## [1] 454
ncol(final_data)
## [1] 4
library(textdata)
library(quanteda)
## Package version: 4.1.0
## Unicode version: 15.1
## ICU version: 74.1
## Parallel computing: 14 of 14 threads used.
## See https://quanteda.io for tutorials and examples.
##
## Attaching package: 'quanteda'
## The following object is masked from 'package:rio':
##
## convert
text_tokenized <- articles_df %>%
select(sentence) %>%
unnest_tokens(word, sentence)
text_tokenized <- articles_df %>%
select(sentence) %>%
mutate(sentence = str_replace_all(sentence, "- ", "")) %>%
unnest_tokens(word, sentence) %>%
filter(!word %in% stop_words$word) %>%
filter(word != "stories_corpus") %>%
filter(!grepl('[0-9]', word))
text_word_ct <- text_tokenized %>%
count(word, sort=TRUE)
text_word_ct
## # A tibble: 27,040 × 2
## word n
## <chr> <int>
## 1 nigeria 2340
## 2 page 1629
## 3 people 1613
## 4 media 1506
## 5 journalists 1505
## 6 government 1469
## 7 dele 1326
## 8 giwa 1326
## 9 nigerian 1180
## 10 lagos 1033
## # ℹ 27,030 more rows
nrc_sentiments <- get_sentiments("nrc")
nrc_sentiments %>% count(sentiment)
## # A tibble: 10 × 2
## sentiment n
## <chr> <int>
## 1 anger 1245
## 2 anticipation 837
## 3 disgust 1056
## 4 fear 1474
## 5 joy 687
## 6 negative 3316
## 7 positive 2308
## 8 sadness 1187
## 9 surprise 532
## 10 trust 1230
nrc_sentiments %>%
group_by(word) %>%
count() %>%
arrange(desc(n)) %>%
distinct()
## # A tibble: 6,453 × 2
## # Groups: word [6,453]
## word n
## <chr> <int>
## 1 feeling 10
## 2 treat 10
## 3 weight 9
## 4 celebrity 8
## 5 intense 8
## 6 obliging 8
## 7 opera 8
## 8 supremacy 8
## 9 vote 8
## 10 death 7
## # ℹ 6,443 more rows
sentiments_all <- text_tokenized %>%
inner_join(nrc_sentiments)
## Joining with `by = join_by(word)`
## Warning in inner_join(., nrc_sentiments): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 13 of `x` matches multiple rows in `y`.
## ℹ Row 8491 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
sentiments_all %>%
group_by(word) %>%
count(sentiment) %>%
arrange(desc(n))
## # A tibble: 9,308 × 3
## # Groups: word [4,171]
## word sentiment n
## <chr> <chr> <int>
## 1 government fear 1469
## 2 government negative 1469
## 3 time anticipation 1014
## 4 journalist positive 966
## 5 president positive 965
## 6 president trust 965
## 7 journalism trust 954
## 8 military fear 826
## 9 police fear 822
## 10 police positive 822
## # ℹ 9,298 more rows
sentiments_all <- text_tokenized %>%
inner_join(nrc_sentiments) %>%
count(sentiment, sort = TRUE) %>%
mutate(pct_total =round(n/sum(n), digits=2))
## Joining with `by = join_by(word)`
## Warning in inner_join(., nrc_sentiments): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 13 of `x` matches multiple rows in `y`.
## ℹ Row 8491 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
sentiments_all
## # A tibble: 10 × 3
## sentiment n pct_total
## <chr> <int> <dbl>
## 1 positive 39226 0.22
## 2 trust 27741 0.16
## 3 negative 24749 0.14
## 4 fear 18302 0.1
## 5 anticipation 16233 0.09
## 6 anger 13082 0.07
## 7 sadness 11421 0.07
## 8 joy 10493 0.06
## 9 surprise 7551 0.04
## 10 disgust 6715 0.04
# Load necessary libraries
library(ggplot2)
library(dplyr)
# Plot the sentiment analysis results
nrc_plot <- sentiments_all %>%
ggplot(aes(x = reorder(sentiment, n), y = n, fill = sentiment)) +
geom_bar(stat = "identity", position = "dodge") +
theme(legend.position = "none") +
labs(
title = "Total Sentiment in Articles About Dele Giwa",
subtitle = " ",
caption = "NRC Sentiment Analysis. Graphic by Kemi Busari, Dec 1, 2024",
x = "Total Sentiment Score",
y = "Score"
) +
theme_minimal(base_size = 14) +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.caption = element_text(hjust = 0, size = 10)
) +
scale_fill_brewer(palette = "Set3") +
coord_flip()
# Print the plot
print(nrc_plot)
nrc_positive <- nrc_sentiments %>%
filter(sentiment == "positive")
dele_positive <- text_tokenized %>%
inner_join(nrc_positive) %>%
count(word, sort = TRUE)
## Joining with `by = join_by(word)`
dele_positive
## # A tibble: 1,663 × 2
## word n
## <chr> <int>
## 1 journalist 966
## 2 president 965
## 3 police 822
## 4 assembly 557
## 5 public 548
## 6 god 489
## 7 university 413
## 8 concord 372
## 9 justice 357
## 10 information 330
## # ℹ 1,653 more rows
#Trust
nrc_trust <- nrc_sentiments %>%
filter(sentiment == "trust")
dele_trust <- text_tokenized %>%
inner_join(nrc_trust) %>%
count(word, sort = TRUE)
## Joining with `by = join_by(word)`
dele_trust
## # A tibble: 912 × 2
## word n
## <chr> <int>
## 1 president 965
## 2 journalism 954
## 3 police 822
## 4 assembly 557
## 5 nation 557
## 6 god 489
## 7 governor 488
## 8 school 476
## 9 law 398
## 10 concord 372
## # ℹ 902 more rows
nrc_negative <- nrc_sentiments %>%
filter(sentiment == "negative")
dele_negative <- text_tokenized %>%
inner_join(nrc_negative) %>%
count(word, sort = TRUE)
## Joining with `by = join_by(word)`
dele_negative
## # A tibble: 2,021 × 2
## word n
## <chr> <int>
## 1 government 1469
## 2 death 730
## 3 words 615
## 4 murder 500
## 5 bomb 499
## 6 late 473
## 7 war 290
## 8 rejected 234
## 9 corruption 215
## 10 lost 213
## # ℹ 2,011 more rows
nrc_fear <- nrc_sentiments %>%
filter(sentiment == "fear")
dele_fear <- text_tokenized %>%
inner_join(nrc_fear) %>%
count(word, sort = TRUE)
## Joining with `by = join_by(word)`
dele_fear
## # A tibble: 988 × 2
## word n
## <chr> <int>
## 1 government 1469
## 2 military 826
## 3 police 822
## 4 death 730
## 5 murder 500
## 6 bomb 499
## 7 god 489
## 8 court 478
## 9 war 290
## 10 killing 205
## # ℹ 978 more rows
nrc_anticipation <- nrc_sentiments %>%
filter(sentiment == "anticipation")
dele_anticipation <- text_tokenized %>%
inner_join(nrc_anticipation) %>%
count(word, sort = TRUE)
## Joining with `by = join_by(word)`
dele_anticipation
## # A tibble: 624 × 2
## word n
## <chr> <int>
## 1 time 1014
## 2 death 730
## 3 public 548
## 4 god 489
## 5 court 478
## 6 daily 416
## 7 university 413
## 8 sun 303
## 9 letter 288
## 10 money 285
## # ℹ 614 more rows
nrc_anger <- nrc_sentiments %>%
filter(sentiment == "anger")
dele_anger <- text_tokenized %>%
inner_join(nrc_anger) %>%
count(word, sort = TRUE)
## Joining with `by = join_by(word)`
dele_anger
## # A tibble: 851 × 2
## word n
## <chr> <int>
## 1 death 730
## 2 words 615
## 3 murder 500
## 4 bomb 499
## 5 court 478
## 6 money 285
## 7 politics 277
## 8 limited 206
## 9 killing 205
## 10 coup 199
## # ℹ 841 more rows
#military_sentiment <- articles_df %>%
#filter(year >= 1986 & year <=1999)
#military_sentiment <- articles_df %>%
#filter(year >= 2000 & year <=2023)
Note: These two codes did not work because my final dataframe did not capture year and publication. I am still trying to figure this out.
#Install and load packages
# install.packages("here")
# install.packages("tidytext")
# install.packages("quanteda")
# install.packages("tm")
# install.packages("topicmodels")
# install.packages("reshape2")
# install.packages("ggplot2")
# install.packages("wordcloud")
# install.packages("pals")
# install.packages("SnowballC")
# install.packages("lda")
# install.packages("ldatuning")
# install.packages("kableExtra")
# install.packages("DT")
# install.packages("flextable")
# install.packages("remotes")
# remotes::install_github("rlesur/klippy")
#install.packages("rio")
#install.packages("readtext")
#install.packages("formattable")
topic_data <- articles_df %>%
select(filename, sentence) %>%
as.data.frame() %>%
rename(doc_id = filename, text= sentence)
# load stopwords
english_stopwords <- readLines("https://slcladal.github.io/resources/stopwords_en.txt", encoding = "UTF-8")
# create corpus object
corpus <- Corpus(DataframeSource(topic_data))
# Preprocessing chain
processedCorpus <- tm_map(corpus, content_transformer(tolower))
processedCorpus <- tm_map(processedCorpus, removeWords, english_stopwords)
processedCorpus <- tm_map(processedCorpus, removePunctuation, preserve_intra_word_dashes = TRUE)
processedCorpus <- tm_map(processedCorpus, removeNumbers)
processedCorpus <- tm_map(processedCorpus, stemDocument, language = "en")
processedCorpus <- tm_map(processedCorpus, stripWhitespace)
#DTM: rows correspond to the documents in the corpus. Columns correspond to the terms in the documents. Cells correspond to the weights of the terms. (Girder)
# compute document term matrix with terms >= minimumFrequency
minimumFrequency <- 5
DTM <- DocumentTermMatrix(processedCorpus, control = list(bounds = list(global = c(minimumFrequency, Inf))))
# have a look at the number of documents and terms in the matrix
dim(DTM)
## [1] 51458 6427
# due to vocabulary pruning, we have empty rows in our DTM
# LDA does not like this. So we remove those docs from the
# DTM and the metadata
sel_idx <- slam::row_sums(DTM) > 0
DTM <- DTM[sel_idx, ]
topic_data <- topic_data[sel_idx, ]
#5 term minimum[1] 1387 3019
#5 term minimum[1] 308597 10339
# number of topics
# K <- 20
K <- 6
# set random number generator seed
set.seed(9161)
#Latent Dirichlet Allocation, LDA
topicModel2 <- LDA(DTM, K, method="Gibbs", control=list(iter = 1000, verbose = 25, alpha = 0.2))
## K = 6; V = 6427; M = 50495
## Sampling 1000 iterations!
## Iteration 25 ...
## Iteration 50 ...
## Iteration 75 ...
## Iteration 100 ...
## Iteration 125 ...
## Iteration 150 ...
## Iteration 175 ...
## Iteration 200 ...
## Iteration 225 ...
## Iteration 250 ...
## Iteration 275 ...
## Iteration 300 ...
## Iteration 325 ...
## Iteration 350 ...
## Iteration 375 ...
## Iteration 400 ...
## Iteration 425 ...
## Iteration 450 ...
## Iteration 475 ...
## Iteration 500 ...
## Iteration 525 ...
## Iteration 550 ...
## Iteration 575 ...
## Iteration 600 ...
## Iteration 625 ...
## Iteration 650 ...
## Iteration 675 ...
## Iteration 700 ...
## Iteration 725 ...
## Iteration 750 ...
## Iteration 775 ...
## Iteration 800 ...
## Iteration 825 ...
## Iteration 850 ...
## Iteration 875 ...
## Iteration 900 ...
## Iteration 925 ...
## Iteration 950 ...
## Iteration 975 ...
## Iteration 1000 ...
## Gibbs sampling completed!
tmResult <- posterior(topicModel2)
theta <- tmResult$topics
beta <- tmResult$terms
topicNames <- apply(terms(topicModel2, 10), 2, paste, collapse = " ") # reset topicnames
# Step 1: Check dimensions
n_theta <- nrow(theta)
n_topicdata<- length(topic_data)
cat("Number of rows in theta: ", n_theta, "\n")
## Number of rows in theta: 50495
cat("Number of documents in textdata: ", n_topicdata, "\n")
## Number of documents in textdata: 2
# Check if textdata contains all the documents in theta
common_ids <- intersect(rownames(theta), topic_data$doc_id) # Assuming textdata has a 'doc_id' column
# Filter textdata to include only the documents present in theta
topicdata_filtered <- topic_data[topic_data$doc_id %in% common_ids, ]
# Check dimensions after filtering
n_topicdata_filtered <- nrow(topicdata_filtered)
cat("Number of documents in filtered textdata: ", n_topicdata_filtered, "\n")
## Number of documents in filtered textdata: 50495
# Align rownames of theta with filtered textdata
theta_aligned <- theta[rownames(theta) %in% topicdata_filtered$doc_id, ]
# Step 2: Combine data
full_data <- data.frame(theta_aligned, decade = topicdata_filtered)
# get mean topic proportions per decade
# topic_proportion_per_decade <- aggregate(theta, by = list(decade = textdata$decade), mean)
# set topic names to aggregated columns
colnames(full_data)[2:(K+1)] <- topicNames
# reshape data frame
vizDataFrame <- melt(full_data)
## Using peopl man god life day time good thing nigeria live, decade.text as id variables
#enframe(): Converts a named list into a dataframe.
topics <- enframe(topicNames, name = "number", value = "text") %>%
unnest(cols = c(text))
topics
## # A tibble: 6 × 2
## number text
## <chr> <chr>
## 1 Topic 1 govern presid countri nigeria militari polit peopl court nigerian nat…
## 2 Topic 2 giwa dele journalist kill murder polic death bomb lago load-dat
## 3 Topic 3 book journal school write ray read year univers nigerian stori
## 4 Topic 4 page media nigeria newspap report nation editor right time news
## 5 Topic 5 state vote elect pdp apc govern voter parti word unit
## 6 Topic 6 peopl man god life day time good thing nigeria live
theta2 <- as.data.frame(theta)
topic1 <- theta2 %>%
rownames_to_column(var = "file") |> # putting the rownames into a new column called file
mutate(file = str_remove(file, "^X"), # Remove leading 'X'
line = str_extract(file, "(?<=\\.txt)\\.\\d+")) |> # Extract number after .txt
mutate(file = str_remove(file, "\\.\\d+$")) |>
rename(topic1 = '1') |>
top_n(20, topic1) |>
arrange(desc(topic1)) |>
select(file, line, topic1)
vizDataFrame <- vizDataFrame %>%
mutate(category = case_when(
str_detect(variable, "govern presid countri nigeria militari polit peopl court nigerian nation") ~ "unresolved_case",
str_detect(variable, "giwa dele journalist kill murder polic death bomb lago load-dat") ~ "assasination",
str_detect(variable, "book journal school write ray read year univers nigerian stori") ~ "remenbrance",
str_detect(variable, "page media nigeria newspap report nation editor right time news") ~ "nigerian_newspapers",
str_detect(variable, "state vote elect pdp apc govern voter parti word unit") ~ "election",
str_detect(variable, "peopl man god life day time good thing nigeria live
") ~ "memory",
TRUE ~ NA_character_
))
Note: I reached a dead end here and would love to get some guidance.
library(readxl)
library(lubridate)
dele_excel <- rio::import("dele_list.XLSX") %>%
janitor::clean_names()
## New names:
## • `Publication` -> `Publication...4`
## • `Publication type` -> `Publication type...5`
## • `Publication` -> `Publication...16`
## • `Publication type` -> `Publication type...17`
# Remove the days of the week from the `publication_date` column
# Convert the publication_date to Date format and remove weekdays (e.g., "Monday", "Tuesday")
dele_excel <- dele_excel %>%
mutate(
published_date = str_remove(published_date, "^\\s*(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),?\\s*") %>%
mdy(), # Adjust mdy() if your date format is MM/DD/YYYY, use dmy() for DD/MM/YYYY
# Create a new column `year` by extracting the year from the `publication_date`
year = year(published_date)
) %>%
# Arrange the dataframe in descending order by publication_date
arrange(desc(published_date))
# View the cleaned data
head(dele_excel)
## title
## 1 Dele Giwa's Death: 37yrs After, Council Chairman Establishes Essay Competition
## 2 Letter bomb did not kill Dele Giwa — Saka
## 3 37 years after Giwa's death: Etsako council chairman set up secondary school essay competition in his honour
## 4 Remembering Dele Giwa
## 5 Dele Giwa's Assassination: 37 Years After -By Ugochukwu Ejinkeonye
## 6 37 Years After, Analyst Blames Babangida, Successive Govts. For Failure To Find Giwa's Killers
## published_date publication_location publication_4
## 1 2023-10-20 International Daily Independent (Nigeria)
## 2 2023-10-20 International Opinion Nigeria
## 3 2023-10-20 International The Sun (Nigeria)
## 4 2023-10-19 International The Nation (Nigeria)
## 5 2023-10-19 International Opinion Nigeria
## 6 2023-10-19 International Daily Independent (Nigeria)
## publication_type_5 length section word_count countries
## 1 News 367 <NA> 367 Africa
## 2 News 350 <NA> 350 Nigeria, Federal Republic of
## 3 News 368 <NA> 368 Nigeria, Federal Republic of
## 4 News 273 <NA> 273 Nigeria, Federal Republic of
## 5 News 1926 <NA> 1926 Nigeria, Federal Republic of
## 6 News 283 <NA> 283 Africa
## byline agg_copyright cite company
## 1 Our Correspondents NA <NA> <NA>
## 2 Opinion Nigeria NA <NA> <NA>
## 3 Cyril NA <NA> <NA>
## 4 <NA> NA <NA> <NA>
## 5 Opinion Nigeria NA <NA> <NA>
## 6 Joy Anigbogu NA <NA> <NA>
## headline
## 1 Dele Giwa's Death: 37yrs After, Council Chairman Establishes Essay Competition
## 2 Letter bomb did not kill Dele Giwa — Saka
## 3 37 years after Giwa's death: Etsako council chairman set up secondary school essay competition in his honour
## 4 Remembering Dele Giwa
## 5 Dele Giwa's Assassination: 37 Years After -By Ugochukwu Ejinkeonye
## 6 37 Years After, Analyst Blames Babangida, Successive Govts. For Failure To Find Giwa's Killers
## hlead
## 1 Dele Giwa's Death: 37yrs After, Council Chairman Establishes Essay Competition Dele Giwa BENIN - As a way of immortalizing late Dele Giwa's name after 37 years of his death, Etsako Central LGA chairman Hon. Solomon Obomighie has established essay competition among secondary schools in the local government in commemoration of his journalism profession.
## 2 Letter bomb did not kill Dele Giwa — Saka Thirty-seven years after the death of the founder of Newswatch, a public affairs analyst and public relations consultant, Mr. Deyemi Saka, yesterday, refuted claims that the veteran journalist, late Dele Giwa, died from a letter bomb.
## 3 37 years after Giwa's death: Etsako council chairman set up secondary school essay competition in his honour From Ighomuaye Lucky, Benin As a way of immortalizing his name after 37 years of his death, Etsako Central LGA chairman Hon. Solomon Obomighie has established Dele Giwa's essay competition among secondary schools in the Local Government in commemoration of his journalism profession.
## 4 Remembering Dele Giwa How time flies? Today makes it exactly 37 years that founding Editor-in-Chief of Newswatch magazine, Dele Giwa, was killed by parcel bomb in his Adeniyi Jones, Ikeja, Lagos home. Time virtually stood still that Sunday, as news spread of his death. Sympathisers rushed to his residence and the Newswatch office then at Oregun to condole with his family and colleagues.
## 5 Dele Giwa's Assassination: 37 Years After -By Ugochukwu Ejinkeonye "Death is…the absence of presence…the endless time of never coming back…a gap you can't see, and when the wind blows through it, it makes no sound" – Tom Stopard In the morning of Monday, October 20, 1986, I was preparing to go to work when a major item on the Anambra Broadcasting Service (ABS) 6.30 news bulletin hit me like a hard object. Mr. Dele Giwa, the founding editor-in-chief of 'Newswatch' magazine, had the previous day been killed and shattered by a letter bomb in his Lagos home. My scream was so loud that my colleague barged into my room to inquire what it was that could have made me to let out such an ear-splitting bellow. We were three young men who had a couple of months earlier been posted from Enugu to Abakaliki to work in the old Anambra State public service, and we had hired a flat in a newly erected two-storey building at the end of Water Works Road, which we shared. My flat-mate, clearly, was not familiar with Giwa's name and work, and so had wondered why his death could elicit such a reaction from me.
## 6 37 Years After, Analyst Blames Babangida, Successive Govts. For Failure To Find Giwa's Killers LAGOS - A Political Analyst, Deyemi Saka has blamed former military President, Ibrahim Babangida and successive governments for failure to find the killers of renowned journalist, Dele Giwa, 37 years after his demise.
## publication_16 publication_type_17 pub_copyright show term
## 1 Daily Independent (Nigeria) Newspaper NA NA NA
## 2 Opinion Nigeria Newswire NA NA NA
## 3 The Sun (Nigeria) Newspaper NA NA NA
## 4 The Nation (Nigeria) Newspaper NA NA NA
## 5 Opinion Nigeria Newswire NA NA NA
## 6 Daily Independent (Nigeria) Newspaper NA NA NA
## ticker year
## 1 NA 2023
## 2 NA 2023
## 3 NA 2023
## 4 NA 2023
## 5 NA 2023
## 6 NA 2023
# Count the number of articles published per year and arrange by year
articles_per_year <- dele_excel %>%
count(year) %>%
arrange(year)
# View the count of articles per year
print(articles_per_year)
## year n
## 1 1986 5
## 2 1990 1
## 3 1992 1
## 4 1993 1
## 5 1995 1
## 6 1996 2
## 7 1998 1
## 8 1999 2
## 9 2000 2
## 10 2001 3
## 11 2002 3
## 12 2005 1
## 13 2006 1
## 14 2009 1
## 15 2010 53
## 16 2011 18
## 17 2012 21
## 18 2013 19
## 19 2014 26
## 20 2015 34
## 21 2016 24
## 22 2017 22
## 23 2018 36
## 24 2019 23
## 25 2020 27
## 26 2021 45
## 27 2022 33
## 28 2023 47
## 29 NA 1
dele_excel <- dele_excel %>%
filter(!is.na(year))
ggplot(articles_per_year, aes(x = year, y = n)) +
geom_line(color = "steelblue", size = 1.2) +
geom_point(color = "black", size = 3) +
labs(
title = "Number of Articles per Year",
subtitle = "Date Created: Nov 23, 2024",
caption = "Graph by Kemi Busari",
x = "Year",
y = "Number of Articles"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 16, face = "bold"),
plot.subtitle = element_text(size = 12),
plot.caption = element_text(size = 10, face = "italic"),
axis.title = element_text(size = 12),
axis.text = element_text(size = 10)
)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).
top_5 <- articles_per_year %>%
top_n(5, n)
ggplot(top_5, aes(x = factor(year), y = n)) +
geom_bar(stat = "identity", fill = "steelblue", color = "black") +
labs(
title = "Top 5 Years with Most Publications",
subtitle = "Date Created: Nov 23, 2024",
caption = "Graph by Kemi Busari",
x = "Year",
y = "Number of Articles"
)
articles_1986_1999 <- dele_excel %>%
filter(year >= 1986 & year <= 1999) %>%
count(year)
#Only 14 articles were published during the military era
articles_2000_2023 <- dele_excel %>%
filter(year >= 2000 & year <= 2023) %>%
count(year)
total_articles_2000_2023 <- sum(articles_2000_2023$n)
dele_excel <- dele_excel %>%
mutate(publication_4 = str_remove_all(publication_4, "\\(.*?\\)"))
dele_excel <- dele_excel %>%
mutate(publication_4 = str_replace(publication_4, "Weekly Trust", "Daily Trust"))
articles_per_newspaper <- dele_excel %>%
count(publication_4) %>%
group_by(publication_4) %>%
summarise(total_articles = sum(n)) %>%
arrange(desc(total_articles))
43 news platforms published about Dele Giwa
top_10_newspapers <- articles_per_newspaper %>%
arrange(desc(total_articles)) %>%
head(10)
ggplot(top_10_newspapers, aes(x = reorder(publication_4, total_articles), y = total_articles)) +
geom_bar(stat = "identity", fill = "steelblue", color = "black") +
geom_text(aes(label = total_articles), vjust = -0.3, size = 5, color = "black") +
labs(
title = "Top 10 Newspapers with Most Articles",
subtitle = "Date Created: Nov 23, 2024",
caption = "Graph by Kemi Busari",
x = "Newspaper",
y = "Number of Articles"
) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 60, hjust = 1)
)
#Summary of final project (word version uploaded to directory) In morning of Monday, October 20, 1986, Dele Giwa, regarded as one of the most critical investigative journalists in Nigeria, was assassinated at his residence in Lagos, Nigeria. While the case is still unresolved, Nigerian journalists at every anniversary (and outside the period) publish news and editorialized articles to commemorate the assassination of Giwa. This study examines these commemorative articles to identify the dominant themes. The study also analyzes differences in the commemoration during the military era (1987 to May 1999) and civilian (1999 to 2023). Inquiry will be guided by these research questions:
#Research Questions 1. What are the dominant themes in the articles commemorating Dele Giwa’s assassination? 2. What are the differences in the commemoration of Dele Giwa between the military era (Oct 1987 to May 1999) and the civilian era (May 1999 to Oct 2023)?
``` r
#Spell out your content analysis plan, including preliminary work on a code book
#The four hundred and fifty four articles were loaded into R, cleaned and prepared for analysis. The unit of analysis are articles about Dele Giwa. The following analysis will be run with the ultimate aim of identifying dominant themes:
#Bigrams: The dataset will be tokenized and then analyzed for bigrams to reveal the top phrases.
#Topic modelling: Latent Dirichlet Allocation (LDA) will be used to cluster words into topics. This will also be used to examine how the themes evolve over time (military vs. civilian era).
#Sentiment analysis: The Afinn dictionary will be used to analyze the overall tone of the articles. (Not sure about this yet because I think this won’t bring anything special)
#Coding scheme
#Below are some preliminary thoughts on a coding scheme based on the literature and my familiarization with the data:
#Bravery and Sacrifice: Mentions of Dele Giwa’s courage, investigative prowess, or ultimate sacrifice for truth and justice.
#Calls for Justice: different expressions advocating for justice or accountability for his assassination.
#Criticism of Authorities: Critical reflections on the failure of successive governments, law enforcement, or judiciary to solve the murder will fall under this category
#Freedom of the Press: Themes highlighting press freedom and the risks journalists face in Nigeria.
#Comparison of Eras: Contrasts between the military and civilian eras in terms of press freedom, accountability, or socio-political environment.
#Role Model: Description of Dele Giwa as an icon of good journalism whose work inspires other journalists.