Check out the Original, Code, and Reconstruction tabs to discover the visual’s challenges and the improvements made.
Objective
As mentioned in the top right corner of the Visual Capitalist (2023) visual, the original objective was to highlight U.S. states that contributed most to America’s mineral production value in 2022. The visual also sheds light on key insights from Southern and Western states and identifies the top producers of gold, silver, copper, and lithium. The goal of this project is to improve the clarity and readability of the original visual, addressing its issues to provide a more effective representation of the data.
Visual Issues
Have a look at the detailed dashboard here - https://rpubs.com/rahil1998/1219448
Reference to original visual
The following code was used to fix the issues identified in the original.
# Adding
library(ggplot2) # For plotting map and bar chart
library(ggiraph) # For Interactive plots (added tooltips)
library(dplyr) # For data manipulation
library(patchwork) # For arranging plots on the plot canvas
library(tidyverse) # For data manipulation
library(albersusa) # For US map
library(ggtext) # For element_markdown() used for alignment
library(ggpubr) # For ggarrange() used for combining plots on canvas (similar to faceting)
library("cowplot") # For ggdraw()
# install.packages("remotes")
# remotes::install_github("hrbrmstr/albersusa", build_vignettes = TRUE)
# Create USGS (2023) in R
Minerals <- data.frame (
States = c("Arizona" ,"Nevada" ,"Texas" ,"California" ,"Minnesota" ,"Alaska" ,"Florida" ,"Utah" ,"Michigan" ,"Missouri" ,"Wyoming" ,"Georgia" ,"Pennsylvania" ,"Ohio" ,"New York" ,"Tennessee" ,"Alabama" ,"North Carolina" ,"Colorado" ,"Wisconsin" ,"Montana" ,"Virginia" ,"South Carolina" ,"New Mexico" ,"Illinois" ,"Indiana" ,"Kansas" ,"Kentucky" ,"Arkansas" ,"Oklahoma" ,"Louisiana" ,"Washington" ,"Idaho" ,"Iowa" ,"Maryland" ,"Oregon" ,"South Dakota" ,"New Jersey" ,"Nebraska" ,"West Virginia" ,"Massachusetts" ,"Mississippi" ,"Connecticut" ,"Hawaii" ,"New Hampshire" ,"Vermont" ,"Maine","North Dakota" ,"Rhode Island" ,"Delaware"),
Values = c(10100 ,8930 ,8030 ,5610 ,4780 ,4510 ,2810 ,3600 ,3360 ,3150 ,2480 ,2320 ,2060 ,1490 ,1950 ,1940 ,1920 ,1900 ,1870 ,1720 ,1600 ,1530 ,1160 ,1470 ,1250 ,1380 ,1170 ,806 ,1100 ,1030 ,1030 ,901 ,371 ,846 ,414 ,693 ,475 ,425 ,256 ,204 ,206 ,225 ,194 ,156 ,135 ,136 ,100 ,105 ,88 ,25),
Rank = c(1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50))
# Remove trailing spaces in States column
Minerals$States <- str_trim(Minerals$States, "right")
# Create a percentage column showing each State's contribution to the nation's total
Minerals <- Minerals %>% mutate(Percentage=paste0(round(Values/sum(Values)*100,1),"%"))
# Create new column for tooltip
Minerals <- Minerals %>% mutate(tooltip_text = paste0(toupper(Minerals$States), "\n","$ ", formatC(Minerals$Values, format="d", big.mark=","), "\n", Minerals$Percentage))
# Create the bar chart
bar_plot <- ggplot(Minerals, aes(x = reorder(Minerals$States, Minerals$Values), y = Minerals$Values,
tooltip = Minerals$tooltip_text, data_id = Minerals$States)) +
geom_col_interactive(color = "grey", fill = "#0072b2", size = 0.5) +
theme_minimal() +
theme(axis.text = element_text(size = 12),
legend.position = "none",
plot.caption = element_markdown(lineheight = 1.2),
plot.title = element_textbox_simple(
hjust = 0,
vjust = 0,
size = 15,
padding = margin(5.5, 5.5, 5.5, 5.5),
margin = margin(0, 0, 5.5, 0)
)) +
scale_y_continuous(label = scales::dollar_format()) +
labs(title = "<b>US States Ranked By Mineral Production Value (2022)</b>",
caption = "<span style = 'font-size:12pt'> <br>**Arizona** made up more than 10% of U.S. mineral production value, and is the leading<br> copper-producing state making up around 70% of domestic copper production <br> <br>
**Nevada** remains the nation's top producer of gold and silver,<br> along with being the only lithium-producing state</span>") +
ylab("USD in Mil. $") +
xlab("") +
coord_flip()
# Get US state data
us_sf <- usa_sf("lcc") %>%
mutate(State = as.character(name))
# Join Our Minerals df with US map df
Map_data <- left_join(us_sf, Minerals, by = c("State" = "States" ), keep = TRUE)
# Create map plot
map_plot <- ggplot() +
geom_sf_interactive(data = Map_data, size =0.125, aes(fill = NULL,data_id = State, tooltip = tooltip_text), color = "white") +
#ggtitle("US States Ranked By Mineral Production Value (2022)")+
theme_void() +
theme(legend.position = "none", plot.title = element_text(hjust = 0.5, vjust = 1)) +
labs(title = "<span style = 'font-size:11pt'> The **Western region** of the US<br> accounted for more than<br> **one-third** of US minerals<br> production value at $35.9 billion </span>",
caption = "<span style = 'font-size:12pt'> The **Southern Region** was the top<br> producer of industrial minerals<br> with a value of $13.2 billion </span>") +
theme(
plot.caption = element_markdown(lineheight = 1.2),
plot.title.position = "plot",
plot.title = element_textbox_simple(lineheight = 0.8, size = 13,
padding = margin(5.5, 5.5, 5.5, 5.5),
margin = margin(0, 0, 5.5, 0),)
)
# Draw bar plot and map plot on same canvas
figure2 <- ggdraw() +
draw_plot(map_plot, x = 0, y = .25, width = .45, height = .6)+
draw_plot(bar_plot, x = .45, y = 0.01, width = .55, height = 0.99)
# Interactive bar chart and US map
p <- girafe(ggobj = figure2,
options = list(
opts_hover(css = ''),
opts_hover_inv(css = "opacity:0.5;"),
opts_sizing(rescale = FALSE)
),
height_svg = 11,
width_svg = 14) %>%
girafe_options(opts_hover(css = "fill:cyan;"))
Data Reference
The following plot fixes the main issues in the original. Please hover over the bars of bar chart or states on US map to view tooltip.
Furthermore, have a look at the detailed dashboard here - https://rpubs.com/rahil1998/1219448