bank <- readr::read_csv("Rounded_Bank.csv")
## Rows: 6 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): country, country_t
## dbl (11): mort_pct, year, population, urban_pct, gdp, agr_pct, girl_to_boy_r...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(ggplot2)
library(patchwork)
library(showtext)
## Loading required package: sysfonts
## Loading required package: showtextdb

Replication

Here is my replication of a plot showing Asia’s Agricultural & Urban Extremes. Here is the link to that plot. https://policyviz.com/hmv_post/urban-population-agriculture-and-land/

left_plot <- ggplot(bank, aes(x = agr_pct, y = reorder(country, -agr_pct), alpha = alpha)) +
  geom_bar(stat = "identity", fill = "dodgerblue", width = 0.6) +
  geom_text(aes(label = ifelse(country %in% c("JAPAN", "BANGLADESH"), scales::percent(agr_pct, accuracy = 1), "")), size = 4, hjust = 1.2, color = "dodgerblue") +
  labs(x = "Agricultural Land (%)", y = NULL) +
  scale_x_reverse(limits = c(1, 0), breaks = seq(0, 1, 1), labels = function(x) x * 100) +
  scale_alpha_identity() +
  theme_minimal() +
  theme(
    axis.text.y = element_blank(),
    axis.title.y = element_blank(),
    axis.title.x = element_text(size = 8, color = "gray70", face = "bold", hjust = 0.93, vjust = 173, margin = margin(b = 10)),
    panel.grid = element_blank(),
    axis.line.x = element_line(color = "gray70"))

middle_annotation <- ggplot() +
  annotate("text", x = 0.5, y = 5.65, label = "JAPAN", size = 3, color = "black", fontface = "bold", alpha = 1) +
  annotate("text", x = 0.5, y = 4.6, label = "INDONESIA", size = 3, color = "black", fontface = "bold", alpha = 0.3) +
  annotate("text", x = 0.5, y = 3.5, label = "PAKISTAN", size = 3, color = "black", fontface = "bold", alpha = 0.3) +
  annotate("text", x = 0.5, y = 2.5, label = "CHINA", size = 3, color = "black", fontface = "bold", alpha = 0.3) +
  annotate("text", x = 0.5, y = 1.4, label = "INDIA", size = 3, color = "black", fontface = "bold", alpha = 0.3) +
  annotate("text", x = 0.5, y = .3, label = "BANGLADESH", size = 3, color = "black", fontface = "bold", alpha = 1) +
  coord_cartesian(xlim = c(0, 1), ylim = c(0, 6)) +
  theme_void()

right_plot <- ggplot(bank, aes(x = urban_pct, y = reorder(country, -agr_pct), alpha = alpha)) +
  geom_bar(stat = "identity", fill = "maroon", width = 0.6) +
  geom_text(aes(label = ifelse(country %in% c("JAPAN", "BANGLADESH"), scales::percent(urban_pct, accuracy = 1), "")), size = 4, hjust = -0.1, color = "maroon") +
  labs(x = "Urban Population (%)", y = NULL) +
  scale_x_continuous(limits = c(0, 1), breaks = seq(0, 1, 1), labels = function(x) x * 100) +
  scale_alpha_identity() +
  theme_minimal() +
  theme(
    axis.title.x = element_text(size = 8, color = "gray70", face = "bold", hjust = 0.075, vjust = 173, margin = margin(b = 10)),
    axis.text.y = element_blank(),
    panel.grid = element_blank(),
    axis.line.x = element_line(color = "gray70"))

combined_plot <- left_plot + middle_annotation + right_plot + plot_layout(widths = c(3,1.2,3))

print(combined_plot)

Improvement

Here is my upgraded version of the plot where I made adjustments to the aesthetics by adding borders around the bars in geom_bar(). I also added a statistical layer by showing USA’s agricultural and urbanization percentage during these years compared to these Asian countries as a baseline. I also added a facet layer to this graph by creating the same graph but for 2022 using data taken from the World Bank, so that you can look at the growth of these countries over time. I also made a thematic stylistic change by making the x-axis lines black instead of gray. I removed all gray sections of the graph. The previous author only wanted you to look at the extremes of the 6 countries, however, I think that the data set is small enough that you can still see the difference between the two most extreme countries without “highlighting” them. I also adjusted the size of the percentages next to the bars to be smaller.

left_plot <- ggplot(bank, aes(x = agr_pct, y = reorder(country, -agr_pct))) +
  geom_bar(stat = "identity", fill = "dodgerblue", width = 0.6, color = "black") +
  geom_vline(xintercept = 0.44, linetype = "dotted", color = "red", size = 0.8)+
  geom_text(aes(label = scales::percent(agr_pct, accuracy = 1) ), size = 3, hjust = 1.2, color = "dodgerblue") +
  labs(x = "Agricultural Land (%)", y = NULL) +
  scale_x_reverse(limits = c(1, 0), breaks = seq(0, 1, 1), labels = function(x) x * 100) +
  annotate("text", x = .9, y = 6.1, label = "2011", size = 6, color = "black", fontface = "bold") +
  annotate("text", x = .52, y = 5.5, label = "USA", size = 3, color = "red", fontface = "bold") +
  theme_minimal() +
  theme(
    axis.text.y = element_blank(),
    axis.title.y = element_blank(),
    axis.title.x = element_text(size = 8, color = "black", face = "bold", hjust = 1, margin = margin(b = 10)),
    panel.grid = element_blank(),
    axis.line.x = element_line(color = "black"))
## 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.
middle_annotation <- ggplot() + 
  annotate("text", x = 0.5, y = 5.65, label = "JAPAN", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 4.6, label = "INDONESIA", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 3.5, label = "PAKISTAN", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 2.5, label = "CHINA", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 1.4, label = "INDIA", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = .3, label = "BANGLADESH", size = 3, color = "black", fontface = "bold") +
  coord_cartesian(xlim = c(0, 1), ylim = c(0, 6)) + 
  theme_void()

# Define the right plot
right_plot <- ggplot(bank, aes(x = urban_pct, y = reorder(country, -agr_pct))) +
  geom_bar(stat = "identity", fill = "maroon", width = 0.6, color = "black") +
  geom_vline(xintercept = 0.81, linetype = "dotted", color = "red", size = 0.8)+
  annotate("text", x = .88, y = 5.5, label = "USA", size = 3, color = "red", fontface = "bold") +
  geom_text(aes(label = scales::percent(urban_pct, accuracy = 1)), size = 3, hjust = -0.1, color = "maroon") +
  labs(x = "Urban Population (%)", y = NULL) +
  scale_x_continuous(limits = c(0, 1), breaks = seq(0, 1, 1), labels = function(x) x * 100) +
  scale_alpha_identity() +
  theme_minimal() +
  theme(
    axis.title.x = element_text(size = 8, color = "black", face = "bold", hjust = 0, margin = margin(b = 10)),
    axis.text.y = element_blank(),
    panel.grid = element_blank(),
    axis.line.x = element_line(color = "black"))

plot1 <- left_plot + middle_annotation + right_plot + plot_layout(widths = c(3, 1.2, 3))

left_2 <- ggplot(bank, aes(x = agr_t, y = reorder(country, -agr_t))) +
  geom_bar(stat = "identity", fill = "dodgerblue", width = 0.6, color = "black") +
  geom_vline(xintercept = 0.45, linetype = "dotted", color = "red", size = 0.8)+
  geom_text(aes(label = scales::percent(agr_t, accuracy = 1) ), size = 3, hjust = 1.2, color = "dodgerblue") +
  labs(x = "Agricultural Land (%)", y = NULL) +
  scale_x_reverse(limits = c(1, 0), breaks = seq(0, 1, 1), labels = function(x) x * 100) +
  annotate("text", x = .9, y = 6.1, label = "2022", size = 6, color = "black", fontface = "bold") +
  annotate("text", x = .52, y = 5.5, label = "USA", size = 3, color = "red", fontface = "bold") +
  theme_minimal() +
  theme(
    axis.text.y = element_blank(),
    axis.title.y = element_blank(),
    axis.title.x = element_text(size = 8, color = "black", face = "bold", hjust = 1, margin = margin(b = 10)),
    panel.grid = element_blank(),
    axis.line.x = element_line(color = "black"))

mid_2 <- ggplot() + 
  annotate("text", x = 0.5, y = 5.65, label = "JAPAN", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 4.6, label = "INDONESIA", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 3.5, label = "PAKISTAN", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 2.5, label = "CHINA", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = 1.4, label = "INDIA", size = 3, color = "black", fontface = "bold") +
  annotate("text", x = 0.5, y = .3, label = "BANGLADESH", size = 3, color = "black", fontface = "bold") +
  coord_cartesian(xlim = c(0, 1), ylim = c(0, 6)) + 
  theme_void()

right_2 <- ggplot(bank, aes(x = urb_t, y = reorder(country, -agr_t))) +
  geom_bar(stat = "identity", fill = "maroon", width = 0.6, color = "black") +
  geom_vline(xintercept = 0.82, linetype = "dotted", color = "red", size = 0.8)+
  annotate("text", x = .88, y = 5.5, label = "USA", size = 3, color = "red", fontface = "bold") +
  geom_text(aes(label = scales::percent(urb_t, accuracy = 1)), 
            size = 3, hjust = -0.1, color = "maroon") +
  labs(x = "Urban Population (%)", y = NULL) +
  scale_x_continuous(limits = c(0, 1), breaks = seq(0, 1, 1), labels = function(x) x * 100) +
  scale_alpha_identity() +
  theme_minimal() +
  theme(
    axis.title.x = element_text(size = 8, color = "black", face = "bold", hjust = 0, margin = margin(b = 10)),
    axis.text.y = element_blank(),
    panel.grid = element_blank(),
    axis.line.x = element_line(color = "black"))

plot2 <- left_2 + mid_2 + right_2 + plot_layout(widths = c(3, 1.2, 3))

print(plot1/plot2)