Mercurial > repos > guerler > charts
comparison heatmap.r @ 53:5a478e171752 draft
Uploaded
author | guerler |
---|---|
date | Thu, 05 Jun 2014 13:38:00 -0400 |
parents | eafc7121f553 |
children | 680cf68098d5 |
comparison
equal
deleted
inserted
replaced
52:e10dbc437d8f | 53:5a478e171752 |
---|---|
1 # limits | |
2 min_limit = 20 | |
3 | |
4 # load sparse matrix package | 1 # load sparse matrix package |
5 suppressPackageStartupMessages(library('Matrix')) | 2 suppressPackageStartupMessages(library('Matrix')) |
6 | 3 |
7 # access a numeric column | 4 # access a numeric column |
8 get_numeric <- function(table, column_key) { | 5 get_numeric <- function(table, column_key) { |
9 column <- as.numeric(column_key) | 6 column <- as.numeric(column_key) |
10 column_data <- sapply( table[column], as.numeric ) | 7 column_data <- suppressWarnings(as.numeric(as.character(table[column][[1]]))) |
11 return (c(column_data)) | 8 return (c(column_data)) |
12 } | 9 } |
13 | 10 |
14 # access a label column | 11 # access a label column |
15 get_label <- function(table, column_key) { | 12 get_label <- function(table, column_key) { |
83 col_order <- hclust(dist(t(my_matrix)))$order | 80 col_order <- hclust(dist(t(my_matrix)))$order |
84 | 81 |
85 # reorder matrix | 82 # reorder matrix |
86 my_matrix <- my_matrix[row_order, col_order] | 83 my_matrix <- my_matrix[row_order, col_order] |
87 | 84 |
88 # get min size | |
89 min_limit = max(as.integer(options$limit), min_limit) | |
90 | |
91 # get max size | |
92 max_row = min(length(row_order), min_limit) | |
93 max_col = min(length(col_order), min_limit) | |
94 | |
95 # transform back to three columns | 85 # transform back to three columns |
96 my_flatmatrix = flatten(my_matrix[1:max_row, 1:max_col]) | 86 my_flatmatrix = flatten(my_matrix) |
97 | 87 |
98 # append to result list | 88 # append to result list |
99 l <- append(l, list(my_flatmatrix$i)) | 89 l <- append(l, list(my_flatmatrix$i)) |
100 l <- append(l, list(my_flatmatrix$j)) | 90 l <- append(l, list(my_flatmatrix$j)) |
101 l <- append(l, list(my_flatmatrix$x)) | 91 l <- append(l, list(my_flatmatrix$x)) |