100% stacked column chart with R
100% stacked column charts are similar to stacked column charts in that categories are represented as vertical bars and series as components of those bars. However, in a 100% stacked column chart, each series bar represents the percentage of the whole to which it belongs, where the total (cumulative) of each stacked bar always equals 100%.
More about: 100% stacked column chart
100% stacked column chart
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
# Loading data
<- read_csv("https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/part_to_a_whole/column_stacked_100perc.csv")
df
# Plot
ggplot(df) +
geom_col(aes(
x = year,
y = percentage,
fill = funding_type
),width = 0.7,
position = position_fill()
+
) scale_fill_unhcr_d(palette = "pal_unhcr") +
scale_x_continuous(breaks = pretty_breaks(n = 9)) +
scale_y_continuous(
expand = expansion(c(0, 0.01)),
labels = percent
+
) labs(
title = "Levels of earmarking | 2012-2020",
caption = "Source: UNHCR\n© UNHCR, The UN Refugee Agency"
+
) theme_unhcr(
grid = "Y",
axis = "x",
axis_title = FALSE
)