geom_axis_flags: Add X-Axis flags to ggplots

Description Usage Arguments Value Note References Examples

View source: R/axis_icon_labels.R

Description

Add X-Axis flags to ggplots

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
geom_axis_flags(
  breaks,
  labels,
  country_icons,
  axis = "x",
  icons_only,
  width = 50,
  lineheight = 3,
  fontface = "bold",
  ...
)

Arguments

breaks

x axis breaks

labels

vector of labels to depict

country_icons

country for which flag to depict, in capital letter ISO-3 format (e.g. DEU for Germany)

axis

"x" or "y", defaults to "x"

width

width of the flag, defaults to 50

lineheight

height of the axis label line

fontface

Font Face for Labels, defaults to "bold"

Value

adds x axis flags to ggplot

Note

You must not call a ggplot theme after the call of geom_axis_flags, otherwise the theme parameter necessary for flag rendering will be overwritten.

References

Flags are under CC-BY licence and are obtained from: https://github.com/eosrei/emojione-color-font

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
options(tidyverse.quiet = TRUE)
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")
  ) %>%
  slice(1:10)
head(wpop2013,10)
ggplot(data = wpop2013 ,
       aes(x = iso3, y = population)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  geom_axis_flags(breaks = wpop2013$iso3,
                   labels = wpop2013$country,
                   country_icons = wpop2013$iso3,
                   width = 30,
                   lineheight = 2,
                   fontface = "bold"
  )

schliebs/ggoxford documentation built on Dec. 25, 2021, 12:17 a.m.