0

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

enter image description here

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.

Community
  • 1
  • 1
Maximilian
  • 4,177
  • 7
  • 46
  • 85
  • I' not sure I get what the "measured value" is exactly and how is related to the ratios. Also, seeing the names for your x and y axes, your plot shall have 5*5 = 25 squares? If so, why each ratio has `length` 50? – alexis_laz Oct 16 '13 at 18:39
  • Thanks for looking into this. The length of 50 is the vector of possible values the "measured" value can be found in. You can think of it as historical data. The "measured" is the current value. Yes 25 squares in the plot as the above (blue/yellow little squares). – Maximilian Oct 16 '13 at 19:32

1 Answers1

2

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:

fig

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

Andy Barbour
  • 8,783
  • 1
  • 24
  • 35
  • 2
    I was about to post something similar. Just to add that, `levelplot(z, col.regions = colorRampPalette(c("green", "red")))` does the same more easily, given `z` has `colnames = letters[c(2,4,6,8,10)]` and `rownames = letters[c(1,3,5,7,9)]`. Using `library(lattice)`. – alexis_laz Oct 16 '13 at 22:17
  • I was aware of the levelplot, but the proposed solution is not what I'm after, unfortunately. Thank you anyways. – Maximilian Oct 17 '13 at 11:15
  • Fair enough @Max. You may get more responses, then, if you revise/edit your question to clarify what you are trying to do. – Andy Barbour Oct 17 '13 at 16:14