knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This is very much work in progress. I apologize for incomplete documentation.
You can install ggoxford from github with:
# install.packages("devtools") devtools::install_github("schliebs/ggoxford")
This is a basic example of how to add country flags to bar plots:
library(tidyverse) library(ggoxford) library(ggtext) wpop2013 <- tidyr::population %>% filter(year == 2013) %>% filter(population > 1e6) %>% mutate(iso3 = countrycode::countrycode(country, origin = "country.name.en", destination = "iso3c") ) head(wpop2013,10)
ggplot(data = wpop2013 %>% slice(1:10), aes(x = iso3, y = population)) + geom_bar(stat = "identity") + theme_minimal() + geom_axis_flags(breaks = wpop2013$iso3, labels = wpop2013$country, country_icons = wpop2013$iso3, axis = "x", width = 30, lineheight = 2, fontface = "bold" )
Now, the package also supports an early version of a y-axis functionality:
ggplot(data = wpop2013 %>% slice(1:5), aes(x = population, y = iso3)) + geom_bar(stat = "identity") + theme_minimal() + geom_axis_flags(breaks = wpop2013$iso3, labels = wpop2013$country, country_icons = wpop2013$iso3, axis = "y", width = 30, lineheight = 2, fontface = "bold" )
Also, the text labels can be disabled via icon_only = T
:
ggplot(data = wpop2013 %>% slice(1:10), aes(x = population, y = iso3)) + geom_bar(stat = "identity") + theme_minimal() + geom_axis_flags(breaks = wpop2013$iso3, labels = wpop2013$country, country_icons = wpop2013$iso3, axis = "y", icons_only = T, width = 30, lineheight = 2, fontface = "bold" )
Or with a few details added (now for the last 10 countries)
set.seed(123) ggplot(data = wpop2013 %>% sample_n(10) , aes(x = iso3, y = population)) + geom_bar(stat = "identity") + geom_text(aes(label = paste0(round(population/1e6),"m")),vjust = -0.25)+ scale_y_continuous(breaks = seq(0e6,80e6,10e6), labels = scales::comma(seq(0e6,80e6,10e6))) + theme_minimal() + labs(x = NULL,y = "Population",title = "Population in 2013")+ geom_axis_flags(breaks = wpop2013$iso3, labels = wpop2013$country, country_icons = wpop2013$iso3, width = 30, lineheight = 2, fontface = "bold" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.