How can I set the colour for a single data point in a scatter plot in R
?
I am using plot
Vary individual data marker colors manually On a chart, select the individual data marker that you want to change. On the Format tab, in the Shape Styles group, click Shape Fill. Do one of the following: To use a different fill color, under Theme Colors or Standard Colors, click the color that you want to use.
To change the color and the size of points, use the following arguments: col : color (hexadecimal color code or color name). For example, col = "blue" or col = "#4F6228" .
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"))
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With