I'm trying to make a waffle plot to use dark mode. This involves changing both the background color and the color of the tile grout. I can't figure out how to do the tile grout.
I'm unable to do any of the normal operations to change the color:
counts <- c(a = 701, b = 1094, c = 1756)
waffle(counts,
rows=50,
size=0.75,
legend_pos="bottom") + theme(legend.key.size=unit(3, "mm"),
rect=element_rect(fill='black',
color='black'),
plot.background=element_rect(fill='black'),
strip.background = element_rect(colour=NA, fill=NA),
panel.background=element_rect(fill='black', color='black'))
There was a pull request to do this, but the person who made it deleted it. It seems like the color is set as a margin color on every tile, since if you increase the waffle function argument size
to size=0
, you get no tile grout:
How do I get the tile grout to be the same black as the background?
This seems pretty hacky, but you can edit what you need in a ggplot
object before printing.
library('waffle')
counts <- c(a = 701, b = 1094, c = 1756)
x <- waffle(counts,
rows=50,
size=0.75,
legend_pos="bottom") + theme(legend.key.size=unit(3, "mm"),
rect=element_rect(fill='black',
color='black'),
plot.background=element_rect(fill='black'),
strip.background = element_rect(colour=NA, fill=NA),
panel.background=element_rect(fill='black', color='black'))
x$layers[[1]]$aes_params$colour <- 'black'
x
A more "ggplot way" would be something like editing/replacing the layer:
x %+replace% geom_tile(inherit.aes = TRUE, color = 'black')
but that does not work. I'm not sure if you can replace a layer in-place without messing up the order. But this is essentially what the hack does.