简体   繁体   中英

How can I visualise two indices that are on the same scale in R?

I have two measures of risk that are negatively correlated eg

x <- runif(30,0,1)
y <- -x + rnorm(30,0,0.1)
plot(x,y) 

I would like to make a combined map of these risk factors but I'm not sure of how to colour code my data. I think I need two colour scales so that each quadrant on my scatterplot would have a different colour.

I've looked up risk heat maps but they generally range from green to red. This results in the top left and bottom right quadrants getting the same colour which is something I don't want.

Since your x's are always non-negative, your points will alw3ays be in quadrant 1 or 4. This is completely determined by whether or not the y value is positive. So you can just make a simple variable to indicate the quadrant using ifelse .

x <- runif(30,0,1)
y <- -x + rnorm(30,0,0.1)

QuadCol = ifelse(y < 0, 1, 2)
plot(x,y, pch=21, bg=QuadCol)

点按象限着色

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