Mostrando entradas con la etiqueta grid. Mostrar todas las entradas
Mostrando entradas con la etiqueta grid. Mostrar todas las entradas

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

2015-11-18

Ajustar el espacio entre el gráfico y la leyenda en ggplot2

Title

Problema

Queremos aumentar la distancia de separación entre el gráfico y la legenda usando el paquete 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))

Solución

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

Referencias

Nube de datos