Figures (Climate Change)

Figures (Climate Change)

Requirements

These six packages are needed to create the visualizations.

library(janitor)  # Cleaning Data
library(tidyverse) # Data Manipulation
library(plm) # Panel Linear Models
library(stargazer) # Table Creation
library(broom) # Tidy data
library(nlme) # Mixed Effects Modeling

This is the final data that we created in the previous script.

p_df <- read.csv("p_df_climate.csv") # Reading in the data
df <- as.data.frame(p_df)
countries <- subset(df, dis == 1) # 1833 country/year occurrences of a disaster

Look at the summary statistics

vars_sum <- c(4,6,7,13:16, 18:24) # Sub-setting the variables of interest
stargazer(df[,vars_sum], type="text", out= "table.html", title="Table 1",
          align = TRUE)
## 
## Table 1
## ============================================================
## Statistic    N      Mean       St. Dev.     Min      Max    
## ------------------------------------------------------------
## reg_corr   3,740    0.500        0.307     0.002    0.971   
## gdppc      3,469   15.369       16.655     0.538   100.865  
## damages    3,741 344,803.100 4,135,080.000   0   210,000,000
## occurences 3,741    1.153        2.109       0       27     
## n_floods   3,741    0.914        1.677       0       25     
## n_drought  3,741    0.091        0.300       0        3     
## oecd       3,741    0.196        0.397       0        1     
## l_dam      3,741    2.297        4.750     0.000   19.163   
## l_aff      3,741    4.726        5.548     0.000   19.663   
## l_death    3,741    1.155        1.854     0.000   12.313   
## dis        3,741    0.490        0.500       0        1     
## flood      3,741    0.441        0.497       0        1     
## drought    3,741    0.087        0.282       0        1     
## ------------------------------------------------------------
country_counts <- table(df$country) # Which countries had less than 21 values
less_than_21 <- subset(country_counts, country_counts < 21)
head(less_than_21) # These countries have been recently established (checks out)
## 
## Palestine/Gaza    South Sudan 
##             14             10

Figure 1

Histrogram of Political Corruption

fig1 <- df  %>%
  ggplot(aes(x=corr)) +
  geom_histogram(binwidth=.05, fill="steelblue", color="white", alpha=0.9) +
  ggtitle("Figure 1", subtitle ="Public Corruption Distribution") +
  theme(plot.title = element_text(hjust = .5, face="bold"),
        plot.subtitle = element_text(hjust = .5)) +
  xlab("Level of Corruption")
fig1

Figure 2

Political Corruption by Year

df_year <- df %>% group_by(year) %>% summarise_at(vars(corr,occurences,
                                                       n_floods,n_earth,n_drought),
                                                  list(mean = mean), na.rm= TRUE)
melt_df <- reshape2::melt(df_year, id.var = "year") 
vars2 <- "corr_mean"
fig2_df <- melt_df %>% filter(variable %in% vars2)
fig2 <- ggplot(fig2_df, aes(x = year, group=1)) + 
  geom_line(aes(color = variable, y= value),lwd= 1.5, show.legend = FALSE) +
  ggtitle("Figure 2", subtitle = "Public Sector Corruption Yearly Mean") + 
  xlab("Year") + labs(colour="Variable") + ylim(.4,.6) + 
  scale_colour_manual(labels = c("Corr"), values = c("brown")) + 
  ylab("Corruption Level") +
  theme(plot.title = element_text(hjust = .5, face="bold"),
        plot.subtitle = element_text(hjust = .5))
fig2

Figure 3

Pie Chart Showing Percentage of Each Disaster.

df_pie <- data.frame(event = c("Floods", "Droughts", "Earthquakes"),
                 count = c(3418, 339, 557))
# calculate percentages
df_pie$percent <- df_pie$count / sum(df_pie$count) * 100

# format labels
df_pie$label <- paste("", df_pie$count, "\n(", round(df_pie$percent, 1), "%)", sep = "")

fig3 <- ggplot(df_pie, aes(x = "", y = count, fill = event)) +
  geom_bar(stat = "identity", color = "white") +
  coord_polar(theta = "y") +
  theme_void() +
  labs(title = "Figure 3", 
       caption = paste("Total:", sum(df_pie$count)), 
       subtitle = "Natural Disaster Events 2000-2020") +
  scale_fill_discrete(name = "Event", labels = paste("", df_pie$event)) +
  geom_text(aes(label = label), position = position_stack(vjust = 0.5)) +
  theme(plot.title = element_text(hjust = .5, face="bold"),
        plot.subtitle = element_text(hjust = .5)) +
  scale_fill_brewer(palette="Set1")
fig3