How to change points individually in plot with for loop having if() inside? R -
I have to make a digit color in conspiracy red if the value of "y" is below zero, otherwise green but thus all Dots get the same color I have tried the following:
x but they are all green:
You pass to the color vector (one for every point) For ifelse : set.seed (1492) # random number generation reproducible X & lt; -c (rnorm (100,) y & lt; -c (rnorm (100)) x & lt; - sort (x, decreasing = FALSE) y & lt; - Sort (y, decrement = FALSE) plot (x, Y, col = ifelse (y & lt; 0, "red", "green"))
Comments
Post a Comment