Topic: Build a circular bar plot to show percentage allocation of a government budget across sectors.
Step 1: Load necessary libraries
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.5.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.1 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(viridis)
Warning: package 'viridis' was built under R version 4.5.3
Loading required package: viridisLite
# Manually creating the data set based on USA spending Explorer FY 2026# 'amount' represents the percentage share of the \$4.4 Trillion total# Line 22:budget_data <-data.frame(sector =c("National Defense", "Medicare", "Health", "Net Interest", "Social Security", "Income Security", "Veterans Benefits", "Other"),percentage =c(22.2, 18.5, 14.0, 12.1, 21.0, 5.2, 4.0, 3.0))# Line 26 & 27: (Split these into two lines for clarity)budget_data <- budget_data %>%arrange(desc(percentage))budget_data$id <-seq(1, nrow(budget_data))
Step 2: Preparing the Circular Geometry
A circular bar plot is technically a stacked bar chart in polar coordinates. To make it look professional (and not like a messy pie chart), we need to calculate the angles for the text labels so they radiate outward.
Calculate the angle for each label
label_data <- budget_datanumber_of_bar <-nrow(label_data)angle <-90-360* (label_data$id -0.5) / number_of_bar# Adjust text alignment so it doesn't flip upside down at the bottom of the circlelabel_data$hjust <-ifelse(angle <-90, 1, 0)label_data$angle <-ifelse(angle <-90, angle +180, angle)
Step 3: Generating the Visualization
This code uses coord_polar to wrap the bars. We use a negative ylim to create the “donut hole” in the middle, which makes it a Circular Bar Plot rather than a standard polar plot.
The Plotting Code
ggplot(budget_data, aes(x =as.factor(id), y = percentage, fill = sector)) +geom_bar(stat ="identity", alpha =0.8) +# Create the center hole (The -10 value controls the size of the inner circle)ylim(-15, 30) +coord_polar(start =0) +# Add the sector labelsgeom_text(data = label_data, aes(x = id, y = percentage +2, label =paste0(sector, " (", percentage, "%)"), hjust = hjust), color ="black", fontface ="bold", size =3, angle = label_data$angle, inherit.aes =FALSE) +# Stylingtheme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),panel.grid =element_blank(),plot.title =element_text(hjust =0.5, face ="bold", size =16),legend.position ="none" ) +scale_fill_viridis_d(option ="mako") +labs(title ="FY 2026 US Government Budget Allocation",caption ="Source: USAspending.gov | Data as of Q1-Q2 2026")
Step 4: Interpretation and Data Insights
Based on the circular bar plot generated from the FY 2026 US Federal Budget data, several key financial priorities and economic realities become evident:
1. Dominance of Mandatory & Defense Spending The visualization clearly illustrates that the bulk of federal spending is concentrated in four major sectors: National Defense (22.2%), Social Security (21.0%), Medicare (18.5%), and Health (14.0%).
Together, these four sectors account for approximately 75.7% of the total $4.4 Trillion budget.
This concentration highlights the “entitlement” nature of the US budget, where the majority of funds are pre-allocated to social safety nets and national security before other discretionary projects are considered.
2. The Weight of Net Interest - A significant insight from the 2026 data is the 12.1% allocation toward Net Interest.
This is not a service-oriented spend; it represents the cost of servicing existing national debt.
Visually, the bar for Net Interest is larger than the combined allocations for Education, Transportation, and Veterans Benefits, signaling a significant fiscal constraint on future government projects.
3. The “Long Tail” of Discretionary Spending The circular bar plot effectively shows the “long tail” of the budget. Sectors like Education, Transportation, and Science appear as much shorter bars.
While these sectors are vital for long-term economic growth, they receive a fraction of the funding compared to the primary “big four” sectors.
The visual disparity in bar lengths emphasizes the difficulty of reallocating funds to these areas without significant policy shifts in mandatory spending.
4. Technical Justification of the Visualization The Circular Bar Plot was selected for this report for the following reasons:
Proportional Comparison: It allows for an immediate visual comparison of category magnitudes in a compact, 360-degree layout.
Visual Engagement: Unlike a standard linear bar chart, the circular format is highly effective for “big picture” reports and presentations, where the goal is to show the distribution of a finite “pie” (the total budget).
Aesthetic Clarity: By using the viridis color scale, we ensure that the sectors are distinguishable even for readers with color vision deficiencies, fulfilling the accessibility requirements of a professional data report.