gpt4 book ai didi

r - 如何增加ggplot2中图例的大小

转载 作者:行者123 更新时间:2023-12-01 12:08:13 25 4
gpt4 key购买 nike

我是 R 中的 ggplot 绘图库的新手,不知道如何增加图例的大小。我知道您可以使用 theme(axis...) 进行轴操作,但我找不到要传递的正确参数!

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

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()

enter image description here

有人有什么建议吗?

示例数据:

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")
)

并将单位更改为最适合您需要的单位。

enter image description here

关于r - 如何增加ggplot2中图例的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54553544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com