Histogram with R
A histogram displays the distribution of data over a continuous interval or specific time period. The height of each bar in a histogram indicates the frequency of data points within the interval/bin.
More about: Histogram
Histogram
# Loading required packages
library(unhcrthemes)
library(tidyverse)
library(scales)
# Loading data
<- read_csv("https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/distribution/histogram.csv")
df
# Plot
ggplot(
df,aes(x = poc_age)
+
) geom_histogram(fill = unhcr_pal(n = 1, "pal_blue")) +
labs(
title = "Age distribution | 2020",
y = "Number of people",
x = "Age",
caption = "Source: Data source here\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 = "Y",
axis = "x",
axis_title = "xy"
)