Skip to content

Instantly share code, notes, and snippets.

@zx8754
Created December 14, 2022 14:05
Show Gist options
  • Save zx8754/ec3e7cddcd18e4f2c6aedab01753f22b to your computer and use it in GitHub Desktop.
Save zx8754/ec3e7cddcd18e4f2c6aedab01753f22b to your computer and use it in GitHub Desktop.
dutch - do not truncate axis
library(ggplot2)
# Countries
#https://worldpopulationreview.com/country-rankings/average-height-by-country
d <- read.table("d.txt", header = TRUE, sep = "\t")
d1 <- d[ d$cca3 %in% c("NLD", "GBR", "USA", "IND", "IDN"),
c("country", "meanHeightMale")]
# Tallest/Shortest person - Wikipedia
# Chandra Bahadur Dangi: 54.6 cm (21.5 in)
# Robert Wadlow: 272 cm (8 ft 11.1 in)
d1 <- rbind(d1, data.frame(country = c("Chandra\nBahadur\nDangi",
"Robert\nWadlow"),
meanHeightMale = c(54.6, 272)))
#order
d1$country <- factor(d1$country,
levels = d1[ order(-d1$meanHeightMale), "country"])
#median age
mm <- median(d$meanHeightMale)
#plot
ggplot(d1, aes(country, meanHeightMale)) +
geom_col(alpha = 0.2, col = "black") +
geom_hline(yintercept = mm, linetype = "dashed", col = "red") +
annotate("text", x = max(as.integer(d1$country)), y = mm,
label = paste("Median", round(mm, 2)),
vjust = -0.1, col = "red") +
scale_y_continuous(breaks = seq(0, 280, 25), expand = c(0, 0)) +
xlab("") + ylab("") +
labs(title = "Average male height (cm)",
subtitle = "per country (incl: tallest/shortest)",
caption = "https://worldpopulationreview.com/country-rankings/average-height-by-country") +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment