Cal Stats
2006-Jun-19 17:10 UTC
[R] Plotting Upper triangle of Matrix with diagonal as the Base
Hi.. I a have a symmetric matrix to plot . I would like to plot only the Upper triangle but with the diagonal as the Base of the rectangle. Is there an easy way to do it. Thanks. Harsh --------------------------------- [[alternative HTML version deleted]]
Greg Snow
2006-Jun-20 20:41 UTC
[R] Plotting Upper triangle of Matrix with diagonal as the Base
Try these functions (modify to suit your needs: tri1 <- function(x){ n <- dim(x)[2] for(i in n:1){ for( j in 1:(n-i+1) ){ cat(sprintf(' %5.2f',x[j,j+i-1])) } cat("\n") } } tri2 <- function(x){ n <- dim(x)[2] for(i in n:1){ cat( rep(' ', 3*(i-1)), sep='',collapse='' ) for( j in 1:(n-i+1) ){ cat(sprintf(' %5.2f',x[j,j+i-1])) } cat("\n") } } tmp <- matrix(1:25,5) # not symmetric, but you get the idea tri1(tmp) tri2(tmp) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Cal Stats Sent: Monday, June 19, 2006 11:11 AM To: r help Subject: [R] Plotting Upper triangle of Matrix with diagonal as the Base Hi.. I a have a symmetric matrix to plot . I would like to plot only the Upper triangle but with the diagonal as the Base of the rectangle. Is there an easy way to do it. Thanks. Harsh --------------------------------- [[alternative HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html