Browse code

Commit made by the Bioconductor Git-SVN bridge.

Commit id: 49eb77cb1b7cfe3a7a437cc779df6cfcbf366342

add_colorbar


Commit id: 45b7e39bae9036f7bda2a117a7c66c3f8eb98e77

remove slash line in heatmap legend <2015-04-30, Thu>


Commit id: 05c85c9dc70bc6f48727c13b34f7d2c5a86f46c8

add space between residue substitution



git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@103301 bc3139a8-67e5-0310-9ffc-ced21a209358

Guangchuang Yu authored on 30/04/2015 07:57:06
Showing 7 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: a phylogenetic tree viewer for different types of tree annotations
4
-Version: 1.1.3
4
+Version: 1.1.4
5 5
 Author: Guangchuang Yu and Tommy Tsan-Yuk Lam
6 6
 Maintainer: Guangchuang Yu <guangchuangyu@gmail.com>
7 7
 Description: ggtree extends the ggplot2 plotting system which implemented the
... ...
@@ -14,6 +14,7 @@ export("%<%")
14 14
 export("%<+%")
15 15
 export("%>%")
16 16
 export(.)
17
+export(add_colorbar)
17 18
 export(aes)
18 19
 export(as.binary)
19 20
 export(collapse)
... ...
@@ -113,6 +114,8 @@ importFrom(ggplot2,geom_segment)
113 114
 importFrom(ggplot2,geom_text)
114 115
 importFrom(ggplot2,geom_tile)
115 116
 importFrom(ggplot2,ggplot)
117
+importFrom(ggplot2,guide_legend)
118
+importFrom(ggplot2,guides)
116 119
 importFrom(ggplot2,labs)
117 120
 importFrom(ggplot2,scale_color_manual)
118 121
 importFrom(ggplot2,scale_fill_discrete)
... ...
@@ -1,5 +1,11 @@
1
+CHANGES IN VERSION 1.1.4
2
+------------------------
3
+ o add_colorbar function <2015-04-30, Thu>
4
+ 
1 5
 CHANGES IN VERSION 1.1.3
2 6
 ------------------------
7
+ o add space between residue substitution (e.g. K123R / E155D) <2015-04-30, Thu>
8
+ o remove slash line in heatmap legend <2015-04-30, Thu>
3 9
  o update vignette to add example of merge_tree <2015-04-29, Wed>
4 10
  
5 11
 CHANGES IN VERSION 1.1.2
... ...
@@ -375,3 +375,38 @@ expand <- function(tree_view, node) {
375 375
     attr(tree_view, clade) <- NULL
376 376
     tree_view
377 377
 }
378
+
379
+##' add colorbar legend
380
+##'
381
+##' 
382
+##' @title add_colorbar
383
+##' @param p tree view
384
+##' @param color output of scale_color function
385
+##' @param x x position
386
+##' @param ymin ymin
387
+##' @param ymax ymax
388
+##' @param font.size font size 
389
+##' @return ggplot2 object
390
+##' @export
391
+##' @importFrom ggplot2 annotate
392
+##' @author Guangchuang Yu
393
+add_colorbar <- function(p, color, x, ymin, ymax, font.size=4) {
394
+    legend <- do.call("cbind", attr(color, "scale"))
395
+    
396
+    legend[,1] <- round(as.numeric(legend[,1]), 2)
397
+    
398
+    ## legend[nrow(legend),1] <- paste(">=", legend[nrow(legend),1])
399
+    
400
+    yy <- seq(ymin, ymax, length.out=nrow(legend)+1)
401
+
402
+    ymin <- yy[1:nrow(legend)]
403
+    ymax <- yy[2:length(yy)]
404
+    y <- (ymin+ymax)/2
405
+
406
+    i <- seq(1, length(y), length.out = 5) %>% round(0)
407
+    offset <- diff(range(p$data$x))/40
408
+    p + annotate("text", x=x+offset*2, y=y[i], label=legend[i,1], size=font.size) +
409
+        annotate("rect", xmin=x, xmax=x+offset, ymin=ymin,
410
+                 ymax = ymax, fill=legend[,2], color=legend[,2]) 
411
+    
412
+}
... ...
@@ -38,6 +38,8 @@ gplot <- function(p, data, low="green", high="red", widths=c(0.5, 0.5), font.siz
38 38
 ##' @importFrom ggplot2 element_text
39 39
 ##' @importFrom ggplot2 geom_tile
40 40
 ##' @importFrom ggplot2 labs
41
+##' @importFrom ggplot2 guides
42
+##' @importFrom ggplot2 guide_legend
41 43
 ##' @importFrom reshape2 melt
42 44
 gplot.heatmap <- function(p, data, low, high, font.size) {
43 45
     isTip <- x <- Var1 <- Var2 <- value <- NULL
... ...
@@ -75,6 +77,7 @@ gplot.heatmap <- function(p, data, low, high, font.size) {
75 77
     p2 <- p2 + theme(panel.margin=unit(0, "null"))
76 78
     p2 <- p2 + theme(plot.margin = unit(c(1, 1, .5, -0.5), "lines"))
77 79
     p2 <- p2 + theme(legend.position = "right")
80
+    p2 <- p2 + guides(fill = guide_legend(override.aes = list(colour = NULL)))
78 81
     ## p2 <- p2 + labs(fill="")
79 82
     
80 83
     return(p2)
... ...
@@ -167,7 +167,7 @@ getSubsLabel <- function(seqs, A, B, translate, removeGap) {
167 167
         return(NULL)
168 168
     }
169 169
     
170
-    res <- paste(AA[ii], ii, BB[ii], sep="", collapse="/")
170
+    res <- paste(AA[ii], ii, BB[ii], sep="", collapse=" / ")
171 171
     return(res)
172 172
 }
173 173
 
174 174
new file mode 100644
... ...
@@ -0,0 +1,31 @@
1
+% Generated by roxygen2 (4.1.1): do not edit by hand
2
+% Please edit documentation in R/ggtree.R
3
+\name{add_colorbar}
4
+\alias{add_colorbar}
5
+\title{add_colorbar}
6
+\usage{
7
+add_colorbar(p, color, x, ymin, ymax, font.size = 4)
8
+}
9
+\arguments{
10
+\item{p}{tree view}
11
+
12
+\item{color}{output of scale_color function}
13
+
14
+\item{x}{x position}
15
+
16
+\item{ymin}{ymin}
17
+
18
+\item{ymax}{ymax}
19
+
20
+\item{font.size}{font size}
21
+}
22
+\value{
23
+ggplot2 object
24
+}
25
+\description{
26
+add colorbar legend
27
+}
28
+\author{
29
+Guangchuang Yu
30
+}
31
+