summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--R/heatmap.R8
-rw-r--r--tests/testthat/test-heatmap.R23
-rw-r--r--tests/testthat/text-heatmap.R5
3 files changed, 28 insertions, 8 deletions
diff --git a/R/heatmap.R b/R/heatmap.R
index 77721ce..c40946f 100644
--- a/R/heatmap.R
+++ b/R/heatmap.R
@@ -75,6 +75,8 @@ heatmap <- function(R, title = NULL, labels = FALSE){
rownames(M) <- R_list$rnames
df <- reshape2::melt(M, na.rm = TRUE)
colnames(df) <- c('i', 'j', 'value')
+ df$i <- as.numeric(df$i)
+ df$j <- as.numeric(df$j)
# And plot it
p <- ggplot2::ggplot(
@@ -82,6 +84,8 @@ heatmap <- function(R, title = NULL, labels = FALSE){
ggplot2::aes(x = .data$j, y = .data$i, fill = .data$value)
) +
ggplot2::geom_tile() +
+ ggplot2::scale_y_reverse() +
+ ggplot2::coord_fixed(clip = 'off') +
ggplot2::scale_fill_gradient2(
low = 'red',
mid = 'white',
@@ -91,8 +95,6 @@ heatmap <- function(R, title = NULL, labels = FALSE){
name = NULL,
guide = 'none'
) +
- ggplot2::scale_y_reverse() +
- ggplot2::coord_fixed(clip = 'off') +
ggplot2::theme_void()
if(!is.null(title)){
@@ -112,7 +114,7 @@ heatmap <- function(R, title = NULL, labels = FALSE){
row_label_df <- data.frame(
j = seq_len(n)[-n],
i = seq_len(n)[-n],
- label = R_list$cnames[-n]
+ label = R_list$rnames[-n]
)
max_nchar <- max(nchar(R_list$cnames))
diff --git a/tests/testthat/test-heatmap.R b/tests/testthat/test-heatmap.R
new file mode 100644
index 0000000..24eae8d
--- /dev/null
+++ b/tests/testthat/test-heatmap.R
@@ -0,0 +1,23 @@
+test_that("returns a ggplot object", {
+ x <- matrix(data = rnorm(100), nrow = 10)
+ p <- heatmap(x)
+ inherits(p, 'ggplot')
+})
+
+test_that("returns a ggplot object with labels", {
+ x <- matrix(data = rnorm(100), nrow = 10)
+ p <- heatmap(x, labels = TRUE)
+ inherits(p, 'ggplot')
+})
+
+test_that("returns a ggplot object with labels and title", {
+ x <- matrix(data = rnorm(100), nrow = 10)
+ p <- heatmap(x, title = 'test', labels = TRUE)
+ inherits(p, 'ggplot')
+})
+
+test_that("returns a ggplot object with title", {
+ x <- matrix(data = rnorm(100), nrow = 10)
+ p <- heatmap(x, title = 'test')
+ inherits(p, 'ggplot')
+})
diff --git a/tests/testthat/text-heatmap.R b/tests/testthat/text-heatmap.R
deleted file mode 100644
index 94ea14e..0000000
--- a/tests/testthat/text-heatmap.R
+++ /dev/null
@@ -1,5 +0,0 @@
-test_that("returns a ggplot object", {
- x <- matrix(data = rnorm(100), nrow = 10)
- p <- heatmap(x)
- inherits(p, 'ggplot')
-})