Setting the color for an individual data point

前端 未结 3 578
一整个雨季
一整个雨季 2020-12-05 07:24

How can I set the colour for a single data point in a scatter plot in R?

I am using plot

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 08:20

    To expand on @Dirk Eddelbuettel's answer, you can use any function for col in the call to plot. For instance, this colors the x==3 point red, leaving all others black:

    x <- 1:5
    plot(x, x, col=ifelse(x==3, "red", "black"))
    

    example 1

    Same goes for point character pch, character expansion cex, etc.

    plot(x, x, col=ifelse(x==3, "red", "black"),
         pch=ifelse(x==3, 19, 1), cex=ifelse(x==3, 2, 1))
    

    example 2

提交回复
热议问题