Line column chart with R

Cedric Vidonne

Lei Chen

Line column chart with R

A line column chart is a type of visualization that combines both line and column charts together, using dual axes displayed on the left and right sides of the chart.

More about: Line column chart


Line 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/change_over_time/line_column.csv")

# Plot
ggplot(data = df) +
  geom_col(aes(year,
    displaced_population,
    fill = "Displaced population"
  ),
  width = 0.7
  ) +
  geom_line(aes(year,
    displaced_proportion * 10,
    color = "Proportion displaced"
  ),
  size = 1
  ) +
  scale_fill_manual(values = setNames(
    unhcr_pal(n = 1, "pal_blue"),
    "Displaced population"
  )) +
  scale_color_manual(values = setNames(
    unhcr_pal(n = 1, "pal_red"),
    "Proportion displaced"
  )) +
  labs(
    title = "Trend of global displacement | 2007 - 2016",
    caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency"
  ) +
  scale_x_continuous(breaks = pretty_breaks(n = nrow(df))) +
  scale_y_continuous("Displaced population (millions)",
    expand = expansion(c(0, 0.2)),
    breaks = pretty_breaks(),
    sec.axis = sec_axis(~ . / 10,
      breaks = pretty_breaks(),
      name = "Proportion displaced (number displaced per 1,000)"
    )
  ) +
  theme_unhcr(
    grid = "Y",
    axis_title = "y"
  )

A line column chart showing trend of global displacement | 2007 - 2016


Related chart with R