[R] Plotting Upper triangle of Matrix with diagonal as the Base

Greg Snow Greg.Snow at intermountainmail.org
Tue Jun 20 22:41:24 CEST 2006


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



More information about the R-help mailing list