Figures (Misinformation)
Required Packages
The first nine packages help create, clean and visualize the data. The final two packages are used as data sources.
library(tidyverse) # Data Manipulation
library(stargazer) # Table Creation
library(reshape2) # Data Aggregation
library(janitor) # Cleaning Data
library(fauxnaif) # Simplifying NA Values
library(gghighlight) # Highlighting Graphics
library(gridExtra) # Graphic Development
library(ggcorrplot) # Correlation Matrix
library(knitr) # Report Generation
library(vdemdata) # V-Dem Data
library(ERT) # ERT Data
Preparing the data
Load in and group the data. After it is time to create the plots.
df <-read.csv("fulldatasetv2.csv")
df_group <- df %>% group_by(country) %>% summarise_at(vars(govdom_osp,pardom_osp,
fordom_osp,edi,edi_rate),
list(mean = mean))
df_year <- df %>% group_by(year) %>% summarise_at(vars(govdom_osp,pardom_osp,
fordom_osp,edi,edi_rate),
list(mean = mean))
Figure 2
vars1 <- c("fordom_osp_mean","govdom_osp_mean", "pardom_osp_mean")
melt_df <- reshape2::melt(df_year, id.var = "year")
fig2_df <- melt_df %>% filter(variable %in% vars1)
fig2 <- ggplot(fig2_df, aes(x = year)) +
geom_line(aes(y = value, colour = variable), lwd= 1.5) +
scale_colour_manual(labels = c("Government","Party", "Foreign"),
values = c("darkblue", "darkred", "darkgreen")) +
ggtitle("Figure 2", subtitle ="False Information: Yearly Means") +
xlab("Year") +
xlim(2000,2020) +
ylab("Value") +
ylim(1.75,3.25) +
labs(colour="Variable") + annotate(
geom = "text", x = 2000, y = 3.2, hjust = 0, vjust = 1, size = 4, label = "Less Disinformation") +
annotate(
geom = "text", x = 2015, y = 1.9, hjust = 0, vjust = 1, size = 4, label = "More Disinformation") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
fig2
Figure 3
vars2 <- c("edi_rate_mean")
fig3_df <- melt_df %>% filter(variable %in% vars2)
fig3 <- ggplot(fig3_df, aes(x = year)) +
geom_line(aes(color = variable, y= value),lwd= 1.5, show.legend = FALSE) +
ggtitle("Figure 3", subtitle = "EDI Rate Yearly Mean") +
xlab("Year") +
xlim(2000,2020) +
ylab("Percentage change in EDI") +
ylim(-1,6) +
labs(colour="Variable") +
scale_colour_manual(labels = c("EDI Rate"), values = c("brown")) +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
fig3
Figure 4
select <- c(5:9, 11:17)
M = cor(df[,select], use="pairwise.complete.obs")
fig4 <- ggcorrplot(M, outline.color = "white", lab = TRUE, tl.cex = 14,
lab_size = 3, lab_col = "black") +
labs(title = "Figure 4", subtitle = "Variable Correlation Matrix") +
theme(plot.title = element_text(hjust = .5, face="bold", size = 18),
plot.subtitle = element_text(hjust = .5, size = 14),
panel.background = element_rect(fill = "white"))
fig4
Figure 5-8, Histograms
fig5 <- df %>% filter(edi_rate >= -5 & edi_rate <= 5) %>%
ggplot(aes(x=edi_rate)) +
geom_histogram(binwidth=1, fill="brown", color="#e9ecef", alpha=0.9) +
ggtitle("Figure 5", subtitle ="EDI Rate (-5 to 5)") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5)) +
xlab("Percentage Change in EDI") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
fig6 <- df %>%
ggplot(aes(x=govdom_osp)) +
geom_histogram(binwidth=.1, fill="brown", color="#e9ecef", alpha=0.9) +
ggtitle("Figure 6", subtitle ="Government Dissemination of False Information") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5)) +
xlab("Level of Government Disinformation") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
fig7 <- df %>%
ggplot(aes(x=fordom_osp)) +
geom_histogram(binwidth=.1, fill="brown", color="#e9ecef", alpha=0.9) +
ggtitle("Figure 7", subtitle ="Foreign Dissemination of False Information") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5)) +
xlab("Level of Foreign Disinformation") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
fig8 <- df %>%
ggplot(aes(x=pardom_osp)) +
geom_histogram(binwidth=.1, fill="brown", color="#e9ecef", alpha=0.9) +
ggtitle("Figure 8", subtitle ="Party Dissemination of False Information") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5)) +
xlab("Level of Party Disinformation") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
grid.arrange(fig5, fig6, fig7, fig8, nrow = 2)
Appendix Figure 1: EDI index by year
append_fig1 <- ggplot(df_year, aes(x=year)) +
geom_line(aes(y=edi_mean),lwd=1.5, color= "brown") +
xlab("Year") +
ylab("EDI Index") +
ggtitle("Appendix Figure 1", subtitle ="Democracy Index (EDI): Yearly Means") +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5)) +
xlim(2000,2020) +
ylim(.45,.55) +
theme(plot.title = element_text(hjust = .5, face="bold"),
plot.subtitle = element_text(hjust = .5),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "gray", linetype = "dotted"))
append_fig1