按照您提供的链接中的示例:
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))
library(grid) # For the function unit
plot <- plot + theme(legend.margin = unit(3, "cm"))