简体   繁体   中英

Colors of points in a base plot conditioned by values in another column

I have a plot where the color of circles (pch=19) at present is either red (when values in conditioning column is >4.5) and black if values are missing (NA).

points(bb$Year,bb$Tot,col=ifelse(bb$rate<4.5|is.na(bb$rate),'black','red'),pch=19,cex=1.7)

在此处输入图像描述

I need a third color, or better, an open circle (pch=21) when values are <=4.5.

Probably simple, but a bit tricky to me.

You need to create an index value that codes for symbol and color:

x <- 0:10
y <- (5 - x)^2
z <- 0:10
z[c(3, 9)] <- NA    # Conditioning variable
sym <- c(1, 16, 16)
clr <- c("black", "black", "red")
idx <- ifelse(is.na(z), 1, ifelse(z <= 4.5, 2, 3))
plot(x, y, pch=sym[idx], col=clr[idx])

阴谋

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM