Change the colour of ablines on ggplot
Posted
by
Sarah
on Stack Overflow
See other posts from Stack Overflow
or by Sarah
Published on 2013-07-03T16:50:59Z
Indexed on
2013/07/03
17:05 UTC
Read the original article
Hit count: 302
Using this data I am fitting a plot:
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")
The two ablines represent the phylogenetically adjusted relationships for each Area trend. I am wondering, is it possible to get the ablines in the same colour palette as their appropriate area data? The first specified is for Area A, the second for Area B.
I used:
g <- ggplot_build(p)
to find out that the first colour is #E41A1C and the second is #377EB8, however when I try to use aes within the +geom_abline command to specify these colours i.e.
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")
It changes the colour of the points and adds to the legend, which I don't want to do.
Any advice would be much appreciated!
© Stack Overflow or respective owner