[R] Green curve/line does not appear on the plot

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sun Jan 10 20:17:25 CET 2021


Dear R-experts,

I dont get any error message but I can't get the green curve/line on the plot.
What is going on ? How to solve my problem ?

Here is the R code :

####################
PIB.hab<-c(12000,34000,25000,43000,12500,32400,76320,45890,76345,90565,76580,45670,23450,34560,65430,65435,56755,87655,90755,45675)
ISQ.2018<-c(564,587,489,421,478,499,521,510,532,476,421,467,539,521,478,532,449,487,465,500)

A=c("Australie","Autriche","Belgique","Canada","Chili","Rép. Tchèque","Danemark","Estonie","Finlande","France","Allemange","Grèce","Hongrie","Islande","Irlande","Israël","Italie","Japon","Corée","Lettonie")
 
plot(ISQ.2018,PIB.hab)

library(basicPlotteR)  

# Add non-overlapping text labels

addTextLabels(ISQ.2018, PIB.hab, A, col.label="black") 


## LOESS FIT
mod=loess(PIB.hab~ISQ.2018,span=1)
yfit=predict(mod,newdata=ISQ.2018)
o=order(ISQ.2018)
lines(ISQ.2018[o],yfit[o],col="blue",lwd=2)

#GAM
library(mgcv)
fit3=gam(PIB.hab~s(ISQ.2018,bs='ps'))
x.new<- seq(range(ISQ.2018)[1], range(ISQ.2018)[2])
gamfit.new <- as.vector(predict.gam(fit3,data.frame(ISQ.2018=x.new),type="response"))
lines(x.new, gamfit.new, col="red", lwd=2)

#Robust GAM
library(robustgam)
true.family <- poisson() 
fit=robustgam(PIB.hab,ISQ.2018, sp=0,family=true.family,smooth.basis='ps',K=3)
x.new <- seq(range(ISQ.2018)[1], range(ISQ.2018)[2])
robustfit.new <- pred.robustgam(fit, data.frame(X=x.new))$predict.values
lines(x.new, robustfit.new, col="green", lwd=2)
####################



More information about the R-help mailing list