Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the color for an individual data point

Tags:

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

I am using plot

like image 446
nit Avatar asked Jan 07 '12 23:01

nit


People also ask

How do I color individual data in Excel?

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.

How do I change the color of a data point in R?

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" .


1 Answers

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

like image 188
Jason Morgan Avatar answered Sep 30 '22 17:09

Jason Morgan