Column chart with R
In a column chart, each category is represented by a vertical rectangle, with the height of the rectangle being proportional to the values being plotted.
More about: Column chart
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/comparison/column.csv")
df
# Plot
ggplot(df) +
geom_col(aes(
x = year,
y = displaced_number
),fill = unhcr_pal(n = 1, "pal_blue"),
width = 0.8
+
) labs(
title = "Total displaced population | 2011 - 2021",
y = "Number of people (in million)",
caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency"
+
) scale_x_continuous(breaks = pretty_breaks(n = 10)) +
scale_y_continuous(
expand = expansion(c(0, 0.1)),
labels = label_number_si()
+
) theme_unhcr(
grid = "Y",
axis = "x",
axis_title = "y"
)
Column chart with labels
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
# Loading data
<- read_csv("https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/comparison/column.csv")
df
# Plot
ggplot(df) +
geom_col(aes(
x = year,
y = displaced_number
),fill = unhcr_pal(n = 1, "pal_blue"),
width = 0.8
+
) geom_text(aes(
x = year,
y = displaced_number,
label = round(displaced_number / 1e6, 1)
),vjust = -1, size = 8 / .pt
+
) labs(
title = "Total displaced population | 2011 - 2021",
subtitle = "Number of people (in million)",
caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency"
+
) scale_x_continuous(breaks = pretty_breaks(n = 10)) +
scale_y_continuous(expand = expansion(c(0, 0.1))) +
theme_unhcr(
grid = FALSE,
axis = "x",
axis_title = FALSE,
axis_text = "x"
)