2020-12-18

How to change the spacing between the legend and the panel in ggplot2

Title

Problema

We want to increase the spacing between the legend and the panel in ggplot2.

library(ggplot2)
xy <- data.frame(x = 1:10, y = 10:1, type = rep(LETTERS[1:2], each=5))
plot <- ggplot(data = xy) +
        geom_point(aes(x = x, y = y, colo r= type))

Solution

We use the argument legend.box.margin to add 20 points to the left.

plot <- plot + theme(legend.box.margin = margin(0, 0, 0, 20))

References

No hay comentarios:

Publicar un comentario

Nube de datos