首页 > 解决方案 > 如何减少ggplot2中的图例框宽度

问题描述

我想减小图例框的宽度。 在此处输入图像描述

我的代码

ggplot() +
  geom_polygon(data =russia,  aes(long, lat, group = group), fill = "grey")+ 
  geom_point(data = prisons, aes(x=lon, y = lat, color=type))+
  theme(legend.justification=c(1,0), legend.position=c(1,0), 
        legend.box.background = element_rect(color="red",size=1), 
        legend.key.size = unit(0.2, "cm"))

这个怎么做?

标签: rggplot2legend

解决方案


尝试使用legend.margin参数。

theme(legend.margin=margin(0,0,0,0))

边距让您分别指定上边距、右边距、下边距和左边距。


推荐阅读