Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
The visualisation chosen depicts the proportion of spending in the 2010 United States Federal Government Budget. The pie graph is intended to display the categories of spending in that year and enable a comparison of those categories. The visualisation provides labels for all the categories from the largest (19.63% of spend) to the smallest (0.02% of spend).
The visualisation chosen had the following three main issues:
Reference * FY2010 Spending by category (2010). Retrieved September 18, 2019, from https://commons.wikimedia.org website: additional detail at https://en.wikipedia.org/wiki/2010_United_States_federal_budget
The following code was used to fix the issues identified in the original.
budget <- read.csv("Budget_2010_USA.csv")
budget$mandatory <- budget$mandatory %>% factor(levels=c(1,0),
labels=c('mandatory', 'discretionary'))
# sort the category variable by budget ammounts in descending order
budget$category <- factor(budget$category, levels=budget$category[order(-budget$amount)])
budget$percentage <- round(100*budget$amount / 3541, 2)
p1 <- ggplot(data=budget, aes(x = category, y = amount, fill = mandatory)) +
labs(title = "2010 United States Federal Government
Budget Spending by Category" ,
x = element_blank(),
y = "$ Amount (Billion)",
caption = "Data source: https://en.wikipedia.org/wiki/2010_United_States_federal_budget")+
geom_bar(position = 'identity', stat='identity') +
geom_text(aes(label= paste0( percentage , " %"),parse = TRUE),
size = 2.5,position=position_dodge(width=.8), hjust=-.3) +
coord_flip() +
theme(legend.position = "bottom", legend.title = element_blank()) +
ylim(0,800)
The following plot fixes the main issues in the original.
Data Reference * https://en.wikipedia.org/wiki/2010_United_States_federal_budget sourced from http://www.gpo.gov/fdsys/pkg/BUDGET-2010-BUD/pdf/BUDGET-2010-BUD.pdf Retrieved September 18, 2019 from http://www.gpo.gov website: