调整图例与主图的间距

Adjusting legend's spacing to main plot

This topic几乎涵盖了R中图例的所有属性。我想知道我们如何增加图例和主要情节之间的间距。

按照您提供的 link 中的示例:

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, color=type))

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