0

I am plotting 9 perspective plots in R using the below code where cm is a list of 9 matrices[11x11]. Now I would like to draw the perspective graph for diagonally upper triangle of each of the corresponding matrix. And also generalise the colour legend for the plots based on the maximum and minimum values (which I already have) from these 9 matrices. Similar question using maptplotlib also answered in SO and I want a R version of it.

Plotting only upper/lower triangle of a heatmap

library(fields)

cm <- list()
i = 1
while(i <= 9){
  cm[[i]] <- matrix(runif(121), 11, 11)
  i = i + 1
}

methods <- c("A", "B", "C", "D", "E", "F", "G", "H", "I")
w_lb <- seq(0, 1, 0.1)
w_dti <- seq(0, 1, 0.1)

with(cm, {
  par(mfrow=c(3,3), xpd=TRUE, bg="white")
  par(mar=c(2,1,2,1) + 0.1)

  i = 1
  while(i <= 9){
    nrz <- nrow(cm[[i]])
    ncz <- ncol(cm[[i]])    
    jet.colors <- colorRampPalette(c("darkgreen", "green", "yellow", "orange", "red", "darkred"))    
    nbcol <- 100
    color <- jet.colors(nbcol)    
    zfacet <- (cm[[i]][-1, -1] + cm[[i]][-1, -ncz] + cm[[i]][-nrz, -1] + cm[[i]][-nrz, -ncz])/4    
    facetcol <- cut(zfacet, nbcol)

    persp(w_lb, w_dti, cm[[i]], 
            theta = -30, phi = 30, expand = 0.85, 
            col=color[facetcol], shade = 0.25, 
            ticktype = "detailed", border = NA, 
            xlab = "LB", ylab = "DTI", zlab="CM", 
            zlim=c(0.0, 1.0)
    )

    image.plot(legend.only=T, zlim=range(zfacet), col=color)
    title(main = methods[[i]])
    i = i + 1    
  }
})
Community
  • 1
  • 1
Joarder Kamal
  • 1,387
  • 1
  • 20
  • 28
  • Can you make your problem reproducible? We don't have access to `cm`. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Roman Luštrik Mar 28 '14 at 10:17
  • @RomanLuštrik sorry for the late reply. I've added the code to generate `cm` using random values. – Joarder Kamal Mar 30 '14 at 20:58

0 Answers0