I was wondering that how I can change the color of certain data points in a scatter plot in R?
So, for example, I want the data point in the 7th, 8th, and 15th row to have a red color and the rest have a black color.
Thanks a lot for your help
I was wondering that how I can change the color of certain data points in a scatter plot in R?
So, for example, I want the data point in the 7th, 8th, and 15th row to have a red color and the rest have a black color.
Thanks a lot for your help
The following will work given that you data is in a data.frame
called "dat".
cols <- rep('black', nrow(dat))
cols[c(7, 8, 15)] <- 'red'
In your plot command set col = cols
.
How about like this?
randomdata<-
data.frame(x=1:20,y=rnorm(20,8,1),col=as.character("black"),stringsAsFactors=FALSE)
randomdata[c(7,8,15),"col"]<-"red"
plot(randomdata$x,randomdata$y,col=randomdata$col)