0

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)

enter image description here

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.

Dag
  • 569
  • 2
  • 5
  • 20
  • Is base plot a requirement? – Ben G Dec 14 '21 at 00:02
  • Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including a representative dataset in a plain text format and all the relevant code. There's a lot happening in that chart which was not generated solely using `points()`. – neilfws Dec 14 '21 at 00:40

1 Answers1

1

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])

Plot

dcarlson
  • 10,936
  • 2
  • 15
  • 18