diff options
| author | Chris Sobczak <chris@sobczak.family> | 2026-07-06 15:52:27 -0700 |
|---|---|---|
| committer | Chris Sobczak <chris@sobczak.family> | 2026-07-06 15:52:27 -0700 |
| commit | 899a2eebc32af2d9d57d1183032b51f42759360d (patch) | |
| tree | 2a3d29cadd9a41a3b3d13bd8d256d69ec0ca2782 /R | |
| parent | 97de1524cc665846a2770d1e5be932889b1d3e7c (diff) | |
Add sorting for heatmap
Diffstat (limited to 'R')
| -rw-r--r-- | R/heatmap.R | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/R/heatmap.R b/R/heatmap.R index cb6c8f8..3351045 100644 --- a/R/heatmap.R +++ b/R/heatmap.R @@ -21,23 +21,34 @@ heatmap <- function(R, title = NULL, labels = FALSE, order = NULL){ R_list <- tryCatch({ if(is.matrix(R)){ Rm <- R - cnames <- colnames(Rm) - rnames <- rownames(Rm) }else{ Rm <- as.matrix(R) - cnames <- colnames(Rm) - rnames <- rownames(Rm) } + + cnames <- colnames(Rm) + rnames <- rownames(Rm) + if(is.null(cnames)){ + cnames <- as.character(seq_len(ncol(Rm))) + } + if(is.null(rnames)){ + rnames <- as.character(seq_len(nrow(Rm))) + } + if(nrow(Rm) == ncol(Rm)){ if(!is.null(order)){ - order <- get_order(Rm) - M <- Rm[order, order] + if(length(order) != nrow(Rm)){ + stop('Provided order is not the same length as the width of R') + }else{ + rownames(Rm) <- rnames + colnames(Rm) <- cnames + Rm <- Rm[order, order] + } } list( - M = M[upper.tri(M)], + Rm = Rm[upper.tri(Rm)], cnames = cnames, rnames = rnames, - p = ncol(M) + p = ncol(Rm) ) }else{ stop('Input must be coercible to a square matrix') @@ -47,13 +58,6 @@ heatmap <- function(R, title = NULL, labels = FALSE, order = NULL){ stop(paste('Invalid input for heatmap:', e$message)) }) - if(is.null(R_list$cnames)){ - R_list$cnames <- as.character(seq_len(R_list$p)) - } - if(is.null(R_list$rnames)){ - R_list$rnames <- as.character(seq_len(R_list$p)) - } - # Now get a df from the upper triangle m <- length(R_list$R) n <- as.integer((1 + sqrt(1 + 8 * m)) / 2) |
