8  geom_f

8.1 geom_function

8.1.1 Package

ggplot2 (Wickham 2016)

8.1.2 Description

Computes and draws a function as a continuous curve.

8.1.3 Understandable aesthetics

required aesthetics

x

y

optional aesthetics

alpha, colour, group, linetype, linewidth

8.1.4 The statistical transformation to use on the data for this layer

stat_prefix

8.1.5 See also

geom_density

8.1.6 Example

ggplot() + 
  geom_function(fun = ~ 0.5*exp(-abs(.x)))

8.2 geom_freqpoly

8.2.1 Package

ggplot2 (Wickham 2016)

8.2.2 Description

Visualise the spread of a single continuous variable by partitioning the x-axis into bins and mapping the frequency of observations within each bin.

8.2.3 Understandable aesthetics

required aesthetics

x

y

optional aesthetics

alpha, colour, group, linetype, linewidth

8.2.4 The statistical transformation to use on the data for this layer

stat_bin for a continuous x variable

stat_count for a discrete x variable

8.2.5 See also

geom_density

8.2.6 Example

worldbankdata |>
  ggplot(aes(x=Electricity, col=Income)) + 
  geom_freqpoly()

8.3 geom_flag

library(ggimage)
worldbankdata.flag <- worldbankdata |>
  filter(Country %in% c("France", "Sweden", "Norway", "Germany", "Switzerland")) |>
  filter(Year == 2000) 
worldbankdata.flag$code.flag <- c("FR", "SE", "NO", "DE", "CH")
worldbankdata.flag |>
ggplot(aes(y = Country, x= Electricity)) + 
  geom_col(stat = 'identity') + 
  geom_flag(y = -2, aes(image = code.flag)) +
  coord_flip() 

Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.