如何在ggplot2中增加图例的大小 [英] How to increase size of legend in ggplot2

查看:2850
本文介绍了如何在ggplot2中增加图例的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Rggplot绘图库的新手,无法解决增加图例大小的问题.我知道您可以使用theme(axis...)进行轴操作,但是我找不到要传递的正确参数!

I'm new to the ggplot plotting library in R and can't work out how to increase the size of my legend. I know you can do axis manipulation with theme(axis...) but I can't find the correct argument to pass!

我用来生成图形的代码在这里:

The code I use to produce the figure is here:

library(ggplot)
library(ggalluvial)

ggplot(data = wrong_cases_all,
       aes(axis1 = cae, axis2 = places,
           y = freq)) +
  scale_x_discrete(limits = c("CAE", "VGG16-Places365"))+
  xlab("Model") +
  geom_alluvium(aes(fill = freq)) +
  geom_stratum() + geom_text(stat = "stratum", label.strata = TRUE) +
  theme_minimal() 

有人有什么秘诀吗?

示例数据:

wrong_cases_all <- read.table(header=TRUE, text = "cae places  freq
1    0      0 19462
2    0      1 23625
3    0      2 14431
4    0      3  9767
5    0      4 14025
6    1      0  8696
7    1      1 88510
8    1      2 12426
9    1      3 33408
10   1      4 16391
11   2      0   540
12   2      1  7908
13   2      2  2132
14   2      3  2429
15   2      4 11558
16   3      0  5215
17   3      1 19993
18   3      2  4361
19   3      3  5984
20   3      4  6993
21   4      0  2258
22   4      1  1382
23   4      2  1409
24   4      3   575
25   4      4  1338")

推荐答案

添加

...
+ theme(
   legend.key.width = unit(1, "cm"),
   legend.key.height = unit(2, "cm")
  )

,然后将单位更改为最适合您的需求.

and change the units to what best fits your needs.

这篇关于如何在ggplot2中增加图例的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆