Browse code

legend_title parameter in gheatmap

Guangchuang Yu authored on 16/05/2019 07:07:03
Showing 4 changed files

... ...
@@ -2,7 +2,7 @@ Package: ggtree
2 2
 Type: Package
3 3
 Title: an R package for visualization and annotation of phylogenetic trees with
4 4
     their covariates and other associated data
5
-Version: 1.17.0
5
+Version: 1.17.1
6 6
 Authors@R: c(
7 7
 	   person("Guangchuang", "Yu",     email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-6485-8781")),
8 8
 	   person("Tommy Tsan-Yuk", "Lam", email = "tylam.tommy@gmail.com",   role = c("aut", "ths")),
... ...
@@ -28,7 +28,7 @@ Imports:
28 28
     rvcheck (>= 0.1.0),
29 29
     tidyr,
30 30
     tidytree (>= 0.2.4),
31
-    treeio (>= 1.7.3),
31
+    treeio (>= 1.8.0),
32 32
     utils
33 33
 Suggests:
34 34
     emojifont,
... ...
@@ -1,3 +1,11 @@
1
+# ggtree 1.17.1
2
+
3
++ add `legend_title` variable in `gheatmap` (2019-05-16, Thu)
4
+
5
+# ggtree 1.16.0
6
+
7
++ Bioconductor 3.9 release
8
+
1 9
 # ggtree 1.15.6
2 10
 
3 11
 + compatible with range is NULL in `geom_range` (2019-04-27, Sat)
... ...
@@ -17,6 +17,7 @@
17 17
 ##' @param colnames_offset_y y offset for column names
18 18
 ##' @param font.size font size of matrix colnames
19 19
 ##' @param hjust hjust for column names (0: align left, 0.5: align center, 1: align righ)
20
+##' @param legend_title title of fill legend
20 21
 ##' @return tree view
21 22
 ##' @importFrom ggplot2 geom_tile
22 23
 ##' @importFrom ggplot2 geom_text
... ...
@@ -31,7 +32,7 @@
31 32
 ##' @author Guangchuang Yu
32 33
 gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color="white",
33 34
                      colnames=TRUE, colnames_position="bottom", colnames_angle=0, colnames_level=NULL,
34
-                     colnames_offset_x = 0, colnames_offset_y = 0, font.size=4, hjust=0.5) {
35
+                     colnames_offset_x = 0, colnames_offset_y = 0, font.size=4, hjust=0.5, legend_title = "value") {
35 36
 
36 37
     colnames_position %<>% match.arg(c("bottom", "top"))
37 38
     variable <- value <- lab <- y <- NULL
... ...
@@ -90,9 +91,9 @@ gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color=
90 91
         p2 <- p + geom_tile(data=dd, aes(x, y, fill=value), width=width, color=color, inherit.aes=FALSE)
91 92
     }
92 93
     if (is(dd$value,"numeric")) {
93
-        p2 <- p2 + scale_fill_gradient(low=low, high=high, na.value=NA) # "white")
94
+        p2 <- p2 + scale_fill_gradient(low=low, high=high, na.value=NA, name = legend_title) # "white")
94 95
     } else {
95
-        p2 <- p2 + scale_fill_discrete(na.value=NA) #"white")
96
+        p2 <- p2 + scale_fill_discrete(na.value=NA, name = legend_title) #"white")
96 97
     }
97 98
 
98 99
     if (colnames) {
... ...
@@ -107,7 +108,7 @@ gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color=
107 108
                              angle=colnames_angle, nudge_x=colnames_offset_x, nudge_y = colnames_offset_y, hjust=hjust)
108 109
     }
109 110
 
110
-    p2 <- p2 + theme(legend.position="right", legend.title=element_blank())
111
+    p2 <- p2 + theme(legend.position="right")
111 112
     ## p2 <- p2 + guides(fill = guide_legend(override.aes = list(colour = NULL)))
112 113
 
113 114
     if (!colnames) {
... ...
@@ -8,7 +8,8 @@ gheatmap(p, data, offset = 0, width = 1, low = "green",
8 8
   high = "red", color = "white", colnames = TRUE,
9 9
   colnames_position = "bottom", colnames_angle = 0,
10 10
   colnames_level = NULL, colnames_offset_x = 0,
11
-  colnames_offset_y = 0, font.size = 4, hjust = 0.5)
11
+  colnames_offset_y = 0, font.size = 4, hjust = 0.5,
12
+  legend_title = "value")
12 13
 }
13 14
 \arguments{
14 15
 \item{p}{tree view}
... ...
@@ -40,6 +41,8 @@ gheatmap(p, data, offset = 0, width = 1, low = "green",
40 41
 \item{font.size}{font size of matrix colnames}
41 42
 
42 43
 \item{hjust}{hjust for column names (0: align left, 0.5: align center, 1: align righ)}
44
+
45
+\item{legend_title}{title of fill legend}
43 46
 }
44 47
 \value{
45 48
 tree view