您的位置:首页 > 其它

R语言:在同一张图作不同曲线

2017-08-24 19:15 127 查看
R语言将两条曲线作在同一张图的方法是:

library(ggplot2)
year<-c(1993,1998,2003,2008)
Res<-c(0.0227,0.0198,0.0155,0.0147)
COPD<-c(0.0138,0.0125,0.0075,0.0069)

#R语言基础包作图
plot(year,Res,col=2,type="b",ylim=c(0.005,0.035),xlab = "Year",ylab ="Morbidity")
lines(year,COPD,col=3,type="b")
legend("topright",pch=c(15,15),legend=c("Respiratory","COPD"),col=c(2,3),bty="n")

#ggplot包作图
dd <- data.frame(year,Res,COPD)
ggplot()+geom_line(data = dd,aes(x = year,y = Res,colour = "Respiratory"),size=1)+
geom_point(data = dd,aes(x = year,y = Res,colour = "Respiratory"),size=3)+
ylim(0.005,0.025)+
geom_line(data = dd,aes(x = year,y = COPD,colour ="COPD"),size=1) +
geom_point(data = dd,aes(x = year,y = COPD,colour = "COPD"),size=3)+
scale_colour_manual("",values = c("Respiratory" = "red","COPD" = "green"))+
xlab("Year")+ylab("Morbidity")+
theme(text=element_text(size=13, family="Comic Sans MS"))




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ggplot2
相关文章推荐