更改Geom_smooth默认图例颜色 [英] change Geom_smooth default legend color
本文介绍了更改Geom_smooth默认图例颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用geom_smooth,它为我提供了默认的图例线颜色蓝色,无法在绘图中使用。
例如,我想在下图中将线型的图例颜色更改为黑色
p>
库(reshape2)
库(ggplot2)
d1< -melt(mtcars,id = c( mpg, cyl))
p <-ggplot(d1,aes(x = mpg,y = value,factor = variable,color = cyl))
p1 <-p + geom_smooth(aes (linetype = as.factor(cyl)),se = F,stat = smooth,method = glm,size = .5,Inherit.aes = T)+
scale_linetype_manual( line type,标签= rp,值= c(1,5,4,3))
解决方案
根据我的评论,如果您在图例中添加了替代项,则可以更改彩色显示器。这应该工作:
p1 <-p + geom_smooth(aes(linetype = as.factor(cyl)),se = F ,stat = smooth,method = glm,size = .5,Inherit.aes = T)+
scale_linetype_manual( line type,labels = c( 100 yr, 50 yr, 25年),值= c(1,5,4,3))+
指南(linetype = guide_legend(override.aes = list(color = black))))
结果为:
I am using geom_smooth and it gives me default legend line color blue that I cannot use in the plot. Is there a way of changing the default color for geom_smooth legend line?
for example, I wand to change the legend colour to black for line type in the following plot
library(reshape2)
library(ggplot2)
d1<-melt(mtcars,id=c("mpg","cyl"))
p<-ggplot(d1,aes(x=mpg,y=value,factor=variable,color=cyl))
p1<-p+geom_smooth(aes(linetype = as.factor(cyl)),se = F,stat = "smooth",method = "glm",size=.5, inherit.aes = T)+
scale_linetype_manual("line type",labels = rp, values=c(1,5,4,3))
解决方案
Per my comment, if you add an override to your legend you can change how the color displays. This should work:
p1<-p+geom_smooth(aes(linetype = as.factor(cyl)),se = F,stat = "smooth",method = "glm",size=.5, inherit.aes = T)+
scale_linetype_manual("line type",labels = c("100 yr", "50 yr", "25 yr"), values=c(1,5,4,3)) +
guides(linetype = guide_legend(override.aes= list(color = "black")))
And the resulting plot is:
这篇关于更改Geom_smooth默认图例颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文