2

I'm trying to create a graph like this:

Plot of filled stacked squares

in ggplot2.

The idea is to visualize the distribution of True/False values, i.e. in the upper bar 3 out of 80 and in the lower bar 2 out of 280. How would one do this in ggplot2?

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
LukasKawerau
  • 1,071
  • 2
  • 23
  • 42

1 Answers1

8

You can use the waffle package.

library(waffle)

parts <- c('TRUE' = 3, 'FALSE' = 77)
p <- waffle(parts, rows = 8, colors = c("black", "grey70"))
p

enter image description here

class(p)
#[1] "gg"     "ggplot"

This is how you could combine two charts like in the graph above

iron(
  waffle(
    c('TRUE' = 3, 'FALSE' = 77),
    colors = c("black", "grey70"),
    size = 0.5,
    pad = 20,
    legend_pos = "none"
  ),
  waffle(
    c('TRUE' = 2, 'FALSE' = 278),
    colors = c("black", "grey70"),
    size = 0.5,
    legend_pos = "bottom"
  )
)

enter image description here

markus
  • 25,843
  • 5
  • 39
  • 58