gpt4 book ai didi

r - 更改 ggplot 上 ablines 的颜色

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

使用 this data我正在拟合一个情节:

p <- ggplot(dat, aes(x=log(Explan), y=Response)) + 
geom_point(aes(group=Area, colour=Area))+
geom_abline(slope=-0.062712, intercept=0.165886)+
geom_abline(slope= -0.052300, intercept=-0.038691)+
scale_x_continuous("log(Mass) (g)")+
theme(axis.title.y=element_text(size=rel(1.2),vjust=0.2),
axis.title.x=element_text(size=rel(1.2),vjust=0.2),
axis.text.x=element_text(size=rel(1.3)),
axis.text.y=element_text(size=rel(1.3)),
text = element_text(size=13)) +
scale_colour_brewer(palette="Set1")

两个 ablines 代表每个区域趋势的系统发育调整关系。我想知道,是否有可能在与相应区域数据相同的调色板中获取 ablines?第一个指定用于区域 A,第二个指定用于区域 B。

我用了:
g <- ggplot_build(p) 

找出第一种颜色是#E41A1C,第二种颜色是#377EB8,但是当我尝试在 +geom_abline 命令中使用 aes 来指定这些颜色时,即
p <- ggplot(dat, aes(x=log(Explan), y=Response)) + 
geom_point(aes(group=Area, colour=Area))+
geom_abline(slope=-0.062712, intercept=0.165886,aes(colour='#E41A1C'))+
geom_abline(slope= -0.052300, intercept=-0.038691,aes(colour=#377EB8))+
scale_x_continuous("log(Mass) (g)")+
theme(axis.title.y=element_text(size=rel(1.2),vjust=0.2),
axis.title.x=element_text(size=rel(1.2),vjust=0.2),
axis.text.x=element_text(size=rel(1.3)),
axis.text.y=element_text(size=rel(1.3)),
text = element_text(size=13)) +
scale_colour_brewer(palette="Set1")

它改变了点的颜色并添加到图例中,这是我不想做的。

任何建议将不胜感激!

最佳答案

由于您是直接设置颜色,因此您不需要 aes()只需使用 colour='#E41A1C' .

+geom_abline(slope=-0.062712, intercept=0.165886,colour='#E41A1C')

关于r - 更改 ggplot 上 ablines 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17453789/

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