geom_point(aes(color = Species))+
scale_color_manual(values = c("orange","green","navy"))+
facet_grid(cols = vars(Species))+
geom_smooth()+
theme_bw()
在ggplot函数的aes添加两个参数:col=Species,fill=Species就行了,修改代码如下:
library(ggplot2)
p<-ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,col=Species,fill=Species))+
geom_point(aes(color = Species))+
scale_color_manual(values = c("orange","green","navy"))+
facet_grid(cols = vars(Species))+
geom_smooth()+
theme_bw( )
plot(p)