I'm having trouble adding vertical spacing to the y axis on a pie chart, without also stretching the color boxes, is there a way to keep the color boxes the same size (square), while increasing the vertical spacing between each element?
I've tried a bunch of different things from modifying theme(legend.text = element_text(margin = margin(t = 1,b = 1, unit ='cm')))
to legend.spacing.y
, and keyheight
, but nothing seems to work so far.
Example:
library(tidyverse)
df1 <- data.frame(Color = c("Blue", "Red", "Green"), pcts = c(.45, .25, .30))
df1$ymax <- cumsum(df1$pcts)
df1$ymin <- lag(df1$ymax, 1, default = 0)
df1 %>% ggplot(aes(ymax = ymax, ymin = ymin, xmax = 4, xmin = 2.85, fill = Color)) +
geom_rect() +
coord_polar(theta = "y") +
theme(legend.text = element_text(margin = margin(t = 1, b = 1, unit = 'cm')))
Also, the below charts are rendered using Cario
, but the default graphics device produces the same result.
Desired legend: