且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ggplot/ggplot2中指定图例框的大小

更新时间:2023-11-26 13:10:16

要指定图例框的大小,可以使用+ theme(legend.key.size = unit(2, "cm")).

To specify the legend box size you could use + theme(legend.key.size = unit(2, "cm")).

library(tidyverse)
tb <- tibble(a = 1:10, b = 10:1, c = rep(1:2, 5))

ggplot(tb, aes(a, b, colour = c)) +
  geom_point() +
  theme(legend.key.size = unit(0.2, "cm"))

更多详细信息和其他修改,请此处并在键宽度下自变量此处.

More details and additional modifications are here and under the keywidth argument here.