ggplot繪圖,代碼如下,分別用四種方法擬合了趨勢線,這四個趨勢線的圖例如何添加?
每種趨勢線都要同時用 顏色、線寬、線型三個要素表示。
求各位指點。
ggplot(mtcars,aes(mpg,wt))+
geom_point()+
geom_smooth(method='lm',se=FALSE,show.legend=TRUE,
linetype=1,color='black',size = 1)+
geom_smooth(formula=y~poly(x,2),se=FALSE,show.legend=TRUE,
linetype=2,color='blue',size=1.2)+
geom_smooth(method='gam',se=FALSE,show.legend=TRUE,
linetype=3,color='gold',size=1.5)+
stat_function(fun = function(x) -0.08*x +5, linetype=4,
show.legend=TRUE,size=2,color='red')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/55706.html
標籤:其他開發語言
