4

I'm trying to make a waffle chart in R using the waffle package. I don't have an even number of entries (49) and I get blank filler squares in my otherwise perfect chart (see purple/blue squares).

Sample Chart

Here is an example of the code:

library('waffle')
basedata <- c(11,38)
names(basedata) <- c("Awsome", "Not Awsome")
waffle(basedata, rows = 2)

Any idea how to remove the blank filler squares?

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
J Stewart
  • 43
  • 2
  • What have you tried so far? Can you share some of your research? – Derek Hopper Dec 27 '17 at 23:24
  • 1
    the default color palette is `RColorBrewer::brewer.pal(n, 'Set2')` where `n` is the number of unique colors, 2 in your case. if you try `RColorBrewer::brewer.pal(2, 'Set2')`, you get a warning that this set requires at least 3 colors, no idea why. you can try `waffle::waffle(c(38, 11), 2, colors = RColorBrewer::brewer.pal(2, 'Set2')[1:2])` or setting _two_ colors of your own. seems like the package authors should have foreseen such a basic case – rawr Dec 27 '17 at 23:25
  • Setting two colors of my own worked (but modifying the brewer colors did not). Thanks! – J Stewart Dec 28 '17 at 15:07

2 Answers2

3

You don't need to "white out" the fillers. It's a known weird behaviour of waffle.

Just pass two colors:

waffle(basedata, rows = 2, colors = c("blue", "red"))

Awesome plot

Roman
  • 4,744
  • 2
  • 16
  • 58
0
waffle(basedata, rows = 2, colors = c("blue", "green", "white"))

or if you want to match the colors to how they were, look up the color scheme at Color Brewer and add the hex codes.

waffle(basedata, rows = 2, colors = c("#fb8072", "#8dd3c7", "white"))

Also, I assume the word "Awesome" isn't included in the real thing, but in case it is, be sure to add that extra "e" in there. :)

jesstme
  • 604
  • 2
  • 10
  • 25