[R] Plot with some countries in red

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Wed May 19 15:14:03 CEST 2021


Dear R-experts,

Here below a toy R code example. I would like some countries (not all of them) "Italy", "Canada", "Greece" and "Norway" to appear in red color. The others remaining black. How can I do that without big changes in my R code ? Indeed, I would like my R code to remain like this as much as possible, for example, end of my R code, I want to keep the non-overlapping text label.

############
A<-c("Italy","Germany","USA","Canada","Turkey","Chile","Mexico","Japan","Norway","Finland","Greece")
B<-c(540,523,589,600,499,567,485,467,543,511,500)
C<-c(470,470,489,492,476,475,455,444,489,456,478)

mod1=loess(C~B,span=0.7)
Bfit=seq(from=min(C),to=max(C),length.out=100)
Afit1=predict(mod1,newdata=Bfit)
plot(B,C,main="Courbe de régression non paramétrique entre ISQ 2015 et ISQ 2018", xlab="score ISQ 2015", ylab="score ISQ 2018 ",type="n")
points(Bfit,Afit1,type="l",lwd=2,col="red")

library(basicPlotteR) 
# Add non-overlapping text labels
addTextLabels(B, C, A, col.label="black")          
############

 

 

 



More information about the R-help mailing list