Reputation: 357
This is a follow-up question that I have concerning a previous problem.
I visualized a 10x10 matrix and colored the squares in the levelplot
according to their value.
This works out fine, however, I would also like to use an if-else-statement for coloring; i.e. if the square value is smaller a certain number the respective square should be colored red otherwise blue.
I am pretty sure this is a very easy problem - I just do not find a solution for it.
Here is an example code to see how it looks like now plus a picture.
library(lattice)
#Build the horizontal and vertical axis information
hor=c("0.0005", "0.001", "0.005", "0.01", "0.05", "0.1", "0.5", "1", "5", "10")
ver=c("1000","2000","3000","4000","5000","6000","7000","8000","9000","10000")
nrowcol=length(ver)
cor = matrix(runif(nrowcol*nrowcol, min=0.4), nrow=nrowcol, ncol=nrowcol, dimnames = list(hor, ver))
for (i in 1:nrowcol) cor[i,i] = 1
rgb.palette <- colorRampPalette(c("blue", "yellow"), space = "rgb")
levelplot(cor, col.regions=rgb.palette(120), cuts=100, at=seq(0,1,0.01),
xlab=expression("DAG depletion rate k"[B49] *" [ s"^"-1"*" ]"),
ylab=expression("PKC activation rate k"[D5] *" [ l / (mol*s) ]"))
Do you have a guess how I can fix this little issues?
Upvotes: 2
Views: 109
Reputation: 132864
levelplot(cor < 0.5, col.regions=c("red", "blue"), cuts = 1,
xlab=expression("DAG depletion rate k"[B49] *" [ s"^"-1"*" ]"),
ylab=expression("PKC activation rate k"[D5] *" [ l / (mol*s) ]"))
I'd not be satisfied with the legend, but I don't know how to change it to a discrete scale with lattice.
Upvotes: 2