gpt4 book ai didi

r - 多图例理由

转载 作者:行者123 更新时间:2023-12-04 18:33:40 25 4
gpt4 key购买 nike

我试图证明 ggplot 中的多个传说是合理的,但没有任何真正的成功。在绘图区域(灰色区域)外显示图例时,对齐方式是正确的。但是,在绘图区域内显示图例时,图例居中(我想让它们左对齐)。我曾尝试关注 this thread但它仍然无法正常工作。

我的例子:

library(ggplot2)

ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl), size = qsec)) +
geom_point(aes(colour = factor(cyl), size = qsec)) +
theme(legend.justification = c(1,0),
legend.position = c(1,0),
legend.margin = unit(0,"lines"),
legend.box = "vertical",
legend.key.size = unit(1,"lines"),
legend.text.align = 0,
legend.title.align = 0)

最佳答案

我们需要添加 legend.box.just = "left"进入您现有的 theme() .

ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl), size = qsec)) +
geom_point(aes(colour = factor(cyl), size = qsec)) +
theme(legend.box.just = "left",
legend.justification = c(1,0),
legend.position = c(1,0),
legend.margin = unit(0,"lines"),
legend.box = "vertical",
legend.key.size = unit(1,"lines"),
legend.text.align = 0,
legend.title.align = 0)

enter image description here

关于r - 多图例理由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36591671/

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