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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.