简体   繁体   中英

Plot ratios as correlation matrix in R

This question is similar to me as this SO post.

Sample data for the ratios:

n=50
ratio1 <- seq(0,1.5,(1.5-0)/(n-1))
ratio2 <- seq(0,2.5,(2.5-0)/(n-1))
ratio3 <- seq(0.5,4.5,(4.5-0.5)/(n-1))
ratio4 <- seq(1,3,(3-1)/(n-1))
ratio5 <- seq(0.7,2,(2-0.7)/(n-1))

To name the ratios:

rname <- c("a/b","c/d","e/f","g/h","i/j") 

so the y-axis labels are c(a,c,e,g,i) and x-axis c(b,d,f,h,j)

Now, let's say the current measured values are:

measure.r <- data.frame(c(0.7,1.5,3.3,2.5,1.5))
colnames(measure.r) <- C("r1","r2","r3","r4","r5")

Now, I would like to plot the measured value within each domain (ratio1, ratio2...etc.) as the referenced SO post about plotting correlation matrix.

So I would like to express the current measured value position within the interval in a color (from green to red, where red means the the upper limit has been reached)

I would like to have the 5 ratios plotted as the correlation matrix referenced here. Where each square would represent state of the measured value (via its color).

在此输入图像描述

I have tried to combine the boxplot bwplot and the lattice levelplot but unsuccessfully.

Hope the above makes sense. Please post any question you may have regarding the description above.

It's pretty hard to tell what you want to do here, but this could get you started

# some fake data
n <- 5
x <- y <- seq_len(n)
z <- outer(x, y, "/")*rnorm(n) # create a matrix of values

# color palette function
pal <- colorRampPalette(c("green", "red"))

# setup plotting regions
layout(matrix(1:2), heights=c(0.7,0.3))

# make an image of the matrix
# ("n" turns off the axis labeling)
image(x, y, z, xaxt="n", yaxt="n", col=pal(11), asp=1, pty="s")
axis(1, x, letters[1:5])
axis(2, y, letters[6:10])

# add a cheap colorbar...
cz <- pretty(range(z))
cx <- seq_along(cz)
image(x=cx, z=matrix(cz), xaxt="n", yaxt="n", col=pal(11))
axis(1, cx, cz)

Gives you something this:

图

So your job would be to make z and modify the code, etc.

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