1

I'm trying to make a waffle chart of raw counts and only two categories. For some reason it makes up enough counts of a mysterious 3rd category to fill out the final column. With three or more categories the final column is partially filled as I intend. How do I make this work with just two categories?

My code:

library(waffle)

test2 <- c(`Group A`= 40, `Group B`= 33)
test3 <- c(`Group A`= 40, `Group B`= 33, `Group c` =10)

#test2 fails, test3 works as intended
waffle(test2)  
waffle(test3)

images below

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Chris Hamson
  • 219
  • 1
  • 2
  • 6
  • By default the `rows = 10`. i.e. if you change it to multiple of 10s, then it gives two categories instead of filling with an empty one `test2 <- c(`Group A`= 40, `Group B`= 20)` – akrun Aug 27 '20 at 21:45
  • @akrun it fills out the rectangle with the mystery third category regardless. waffle(test2, rows=20) also fills the rectangle. Perhaps I don't understand your answer – Chris Hamson Aug 27 '20 at 22:02
  • If you use the example I showed, it is giving only 2 categories (for me) – akrun Aug 27 '20 at 22:02
  • When I run your code I get 2 categories and full columns. That would be great if that was my data. Did you cut n' paste my code as is? I can't use your code as I need my data to be my actual data and not to be a multiple of 10 (or any other row number) – Chris Hamson Aug 27 '20 at 22:07
  • 1
    Yes, it seems to be a bug in the source code – akrun Aug 27 '20 at 22:08
  • Issue submitted in github https://github.com/hrbrmstr/waffle/issues/77 – Chris Hamson Aug 27 '20 at 22:48

1 Answers1

2

As far as I get it the issue is related to the fact that the default color brewer palette returns three colors, i.e RColorBrewer::brewer.pal(2, "Set2") will return a vector of three colors. To solve this issue you have to explicitly specify that you want to have only two colors in your waffle chart. Try this:

library(waffle)
#> Loading required package: ggplot2

test2 <- c(`Group A`= 40, `Group B`= 33)

waffle(test2, colors = c(RColorBrewer::brewer.pal(3, "Set2")[1:2]))  

stefan
  • 90,330
  • 6
  • 25
  • 51