I have a two-part waffle plot with a lot of little squares, and a legend that contains two squares. I would like to make the sizes of all of these squares to be the same.
There was an issue opened on GitHub about this, and the repo owner said that since waffle() returns a ggplot2 object, we can use guide() to do this.
I tried searching on documentation to do this and came up with
library(waffle)
phrase_count = 17345/10000
all_count = (22784085 - phrase_count)/10000
my_waffle = waffle(c("All"=all_count, "Phrases"=phrase_count),
rows=43,
size=0.6,
colors=c("#969696", "pink", "white"),
flip=TRUE)
my_waffle + guides(colour=guide_legend(override.aes = list(size=0.6)))
but this doesn't affect the size of the legend. I've seen people use color
, colour
, or shape
, but none of these arguments work for me.
How do I get the size of squares in the legend to be the same as the size of the squares in the plot itself?
Try setting theme()
for your legend key as the waffle object is from ggplot2
nature as mentioned in comments by @Waldi:
#Code
my_waffle <- my_waffle + theme(legend.key.size = unit(3, "mm"))
Output:
Or maybe this:
#Code 2
my_waffle + theme(legend.key.height = unit(0.2, "cm"),
legend.key.width = unit(0.3, "cm"))
Output: