Ordered column chart with R
An ordered column chart is a chart in which each category is represented by a vertical rectangle, with the height of the rectangle being ordered and proportional to the values being plotted.
More about: Ordered column chart
Ordered column chart
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
# Loading data
df <- read_csv("https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/ranking/column_ordered.csv")
# Plot
ggplot(df) +
geom_col(aes(
x = reorder(country_origin, -returnee_number),
y = returnee_number
),
fill = unhcr_pal(n = 1, "pal_blue"),
width = 0.8
) +
labs(
title = "Refugee returns by country of origin (top 5) | 2020",
y = "Number of people",
caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency"
) +
scale_y_continuous(
expand = expansion(c(0, 0.1)),
breaks = pretty_breaks(),
labels = label_number_si()
) +
theme_unhcr(
grid = "Y",
axis = "x",
axis_title = "y"
)Ordered column chart with labels
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
# Loading data
df <- read_csv("https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/ranking/column_ordered.csv")
# Plot
ggplot(df) +
geom_col(aes(
x = reorder(country_origin, -returnee_number),
y = returnee_number
),
fill = unhcr_pal(n = 1, "pal_blue"),
width = 0.8
) +
geom_text(aes(
x = reorder(country_origin, -returnee_number),
y = returnee_number,
label = format(returnee_number,
big.mark = ",",
scientific = FALSE
)
),
vjust = -1,
size = 8 / .pt
) +
labs(
title = "Refugee returns by country of origin (top 5) | 2020",
subtitle = "Number of people",
caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency"
) +
scale_y_continuous(
expand = expansion(c(0, 0.1))
) +
theme_unhcr(
grid = FALSE,
axis = "x",
axis_title = FALSE,
axis_text = "x"
)