Commit id: 73171be89c157222e8e71e85daa8a37ce509a4e2
add border argument in anno_* family functions
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ComplexHeatmap@107201 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -5,6 +5,7 @@ |
5 | 5 |
# == param |
6 | 6 |
# -x a vector of numeric values. |
7 | 7 |
# -which is the annotation a column annotation or a row annotation? |
8 |
+# -border whether show border of the annotation compoment |
|
8 | 9 |
# -gp graphic parameters. |
9 | 10 |
# -pch point type. |
10 | 11 |
# -size point size. |
... | ... |
@@ -20,7 +21,7 @@ |
20 | 21 |
# == author |
21 | 22 |
# Zuguang Gu <z.gu@dkfz.de> |
22 | 23 |
# |
23 |
-anno_points = function(x, which = c("column", "row"), gp = gpar(), pch = 16, |
|
24 |
+anno_points = function(x, which = c("column", "row"), border = TRUE, gp = gpar(), pch = 16, |
|
24 | 25 |
size = unit(2, "mm"), axis = FALSE, axis_side = NULL, |
25 | 26 |
axis_gp = gpar(fontsize = 8), ...) { |
26 | 27 |
|
... | ... |
@@ -54,7 +55,7 @@ anno_points = function(x, which = c("column", "row"), gp = gpar(), pch = 16, |
54 | 55 |
} |
55 | 56 |
|
56 | 57 |
pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5))) |
57 |
- grid.rect() |
|
58 |
+ if(border) grid.rect() |
|
58 | 59 |
grid.points(x[index], n - seq_along(index) + 1, gp = gp, default.units = "native", pch = pch, size = size) |
59 | 60 |
if(axis) { |
60 | 61 |
if(k == 1 && axis_side == "top") { |
... | ... |
@@ -70,7 +71,7 @@ anno_points = function(x, which = c("column", "row"), gp = gpar(), pch = 16, |
70 | 71 |
gp = subset_gp(gp, index) |
71 | 72 |
|
72 | 73 |
pushViewport(viewport(xscale = c(0.5, n+0.5), yscale = data_scale)) |
73 |
- grid.rect() |
|
74 |
+ if(border) grid.rect() |
|
74 | 75 |
grid.points(seq_along(index), x[index], gp = gp, default.units = "native", pch = pch, size = size) |
75 | 76 |
if(axis) { |
76 | 77 |
if(axis_side == "left") { |
... | ... |
@@ -89,6 +90,8 @@ anno_points = function(x, which = c("column", "row"), gp = gpar(), pch = 16, |
89 | 90 |
# == param |
90 | 91 |
# -x a vector of numeric values. |
91 | 92 |
# -which is the annotation a column annotation or a row annotation? |
93 |
+# -border whether show border of the annotation compoment |
|
94 |
+# -bar_width relative width of the bars, should less than one |
|
92 | 95 |
# -gp graphic parameters. |
93 | 96 |
# -axis whether add axis |
94 | 97 |
# -axis_side if it is placed as column annotation, value can only be "left" or "right". |
... | ... |
@@ -102,14 +105,14 @@ anno_points = function(x, which = c("column", "row"), gp = gpar(), pch = 16, |
102 | 105 |
# == author |
103 | 106 |
# Zuguang Gu <z.gu@dkfz.de> |
104 | 107 |
# |
105 |
-anno_barplot = function(x, which = c("column", "row"), |
|
108 |
+anno_barplot = function(x, which = c("column", "row"), border = TRUE, bar_width = 0.6, |
|
106 | 109 |
gp = gpar(fill = "#CCCCCC"), axis = FALSE, axis_side = NULL, |
107 | 110 |
axis_gp = gpar(fontsize = 8), ...) { |
108 | 111 |
|
109 | 112 |
x = x |
110 | 113 |
which = match.arg(which)[1] |
111 | 114 |
|
112 |
- factor = 0.6 |
|
115 |
+ factor = bar_width |
|
113 | 116 |
data_scale = range(x) |
114 | 117 |
data_scale = data_scale + c(-0.05, 0.05)*(data_scale[2] - data_scale[1]) |
115 | 118 |
gp = check_gp(gp) |
... | ... |
@@ -138,7 +141,7 @@ anno_barplot = function(x, which = c("column", "row"), |
138 | 141 |
} |
139 | 142 |
|
140 | 143 |
pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5))) |
141 |
- grid.rect() |
|
144 |
+ if(border) grid.rect() |
|
142 | 145 |
grid.rect(x = data_scale[1], y = n - seq_along(index) + 1, width = x[index] - data_scale[1], height = 1*factor, just = "left", default.units = "native", gp = gp) |
143 | 146 |
if(axis) { |
144 | 147 |
if(k == 1 && axis_side == "top") { |
... | ... |
@@ -155,7 +158,7 @@ anno_barplot = function(x, which = c("column", "row"), |
155 | 158 |
gp = subset_gp(gp, index) |
156 | 159 |
|
157 | 160 |
pushViewport(viewport(xscale = c(0.5, n+0.5), yscale = data_scale)) |
158 |
- grid.rect() |
|
161 |
+ if(border) grid.rect() |
|
159 | 162 |
grid.rect(x = seq_along(index), y = data_scale[1], height = x[index] - data_scale[1], width = 1*factor, just = "bottom", default.units = "native", gp = gp) |
160 | 163 |
if(axis) { |
161 | 164 |
if(axis_side == "left") { |
... | ... |
@@ -175,6 +178,7 @@ anno_barplot = function(x, which = c("column", "row"), |
175 | 178 |
# -x a matrix or a list. If ``x`` is a matrix and if ``which`` is ``column``, statistics for boxplot |
176 | 179 |
# is calculated by columns, if ``which`` is ``row``, the calculation is by rows. |
177 | 180 |
# -which is the annotation a column annotation or a row annotation? |
181 |
+# -border whether show border of the annotation compoment |
|
178 | 182 |
# -gp graphic parameters |
179 | 183 |
# -pch point type |
180 | 184 |
# -size point size |
... | ... |
@@ -189,7 +193,8 @@ anno_barplot = function(x, which = c("column", "row"), |
189 | 193 |
# == author |
190 | 194 |
# Zuguang Gu <z.gu@dkfz.de> |
191 | 195 |
# |
192 |
-anno_boxplot = function(x, which = c("column", "row"), gp = gpar(fill = "#CCCCCC"), |
|
196 |
+anno_boxplot = function(x, which = c("column", "row"), border = TRUE, |
|
197 |
+ gp = gpar(fill = "#CCCCCC"), |
|
193 | 198 |
pch = 16, size = unit(2, "mm"), axis = FALSE, axis_side = NULL, |
194 | 199 |
axis_gp = gpar(fontsize = 8)) { |
195 | 200 |
|
... | ... |
@@ -234,7 +239,7 @@ anno_boxplot = function(x, which = c("column", "row"), gp = gpar(fill = "#CCCCCC |
234 | 239 |
stop(paste0("Length of index should be ", ncol(boxplot_stats))) |
235 | 240 |
} |
236 | 241 |
pushViewport(viewport(xscale = data_scale, yscale = c(0.5, n+0.5))) |
237 |
- grid.rect() |
|
242 |
+ if(border) grid.rect() |
|
238 | 243 |
grid.segments(boxplot_stats[5, ], n - seq_along(index) + 1 - 0.5*factor, |
239 | 244 |
boxplot_stats[5, ], n - seq_along(index) + 1 + 0.5*factor, default.units = "native", gp = gp) |
240 | 245 |
grid.segments(boxplot_stats[5, ], n - seq_along(index) + 1, |
... | ... |
@@ -271,7 +276,7 @@ anno_boxplot = function(x, which = c("column", "row"), gp = gpar(fill = "#CCCCCC |
271 | 276 |
stop(paste0("Length of index should be ", ncol(boxplot_stats))) |
272 | 277 |
} |
273 | 278 |
pushViewport(viewport(xscale = c(0.5, n+0.5), yscale = data_scale)) |
274 |
- grid.rect() |
|
279 |
+ if(border) grid.rect() |
|
275 | 280 |
grid.segments(seq_along(index) - 0.5*factor, boxplot_stats[5, ], |
276 | 281 |
seq_along(index) + 0.5*factor, boxplot_stats[5, ], default.units = "native", gp = gp) |
277 | 282 |
grid.segments(seq_along(index), boxplot_stats[5, ], |
... | ... |
@@ -33,6 +33,7 @@ Zuguang Gu <z.gu@dkfz.de> |
33 | 33 |
|
34 | 34 |
|
35 | 35 |
|
36 |
+ |
|
36 | 37 |
There is no public constructor method for the \code{\link{HeatmapList-class}}.} |
37 | 38 |
\examples{ |
38 | 39 |
|
... | ... |
@@ -41,5 +42,6 @@ There is no public constructor method for the \code{\link{HeatmapList-class}}.} |
41 | 42 |
|
42 | 43 |
|
43 | 44 |
|
45 |
+ |
|
44 | 46 |
# no example |
45 | 47 |
NULL} |
... | ... |
@@ -9,13 +9,15 @@ Using barplot as annotation |
9 | 9 |
|
10 | 10 |
} |
11 | 11 |
\usage{ |
12 |
-anno_barplot(x, which = c("column", "row"), |
|
12 |
+anno_barplot(x, which = c("column", "row"), border = TRUE, bar_width = 0.6, |
|
13 | 13 |
gp = gpar(fill = "#CCCCCC"), axis = FALSE, axis_side = NULL, |
14 | 14 |
axis_gp = gpar(fontsize = 8), ...)} |
15 | 15 |
\arguments{ |
16 | 16 |
|
17 | 17 |
\item{x}{a vector of numeric values.} |
18 | 18 |
\item{which}{is the annotation a column annotation or a row annotation?} |
19 |
+ \item{border}{whether show border of the annotation compoment} |
|
20 |
+ \item{bar_width}{relative width of the bars, should less than one} |
|
19 | 21 |
\item{gp}{graphic parameters.} |
20 | 22 |
\item{axis}{whether add axis} |
21 | 23 |
\item{axis_side}{if it is placed as column annotation, value can only be "left" or "right".If it is placed as row annotation, value can only be "bottom" or "top".} |
... | ... |
@@ -37,6 +39,7 @@ Zuguang Gu <z.gu@dkfz.de> |
37 | 39 |
|
38 | 40 |
|
39 | 41 |
|
42 |
+ |
|
40 | 43 |
f = anno_barplot(rnorm(10)) |
41 | 44 |
grid.newpage(); f(1:10) |
42 | 45 |
|
... | ... |
@@ -9,13 +9,15 @@ Using boxplot as annotation |
9 | 9 |
|
10 | 10 |
} |
11 | 11 |
\usage{ |
12 |
-anno_boxplot(x, which = c("column", "row"), gp = gpar(fill = "#CCCCCC"), |
|
12 |
+anno_boxplot(x, which = c("column", "row"), border = TRUE, |
|
13 |
+ gp = gpar(fill = "#CCCCCC"), |
|
13 | 14 |
pch = 16, size = unit(2, "mm"), axis = FALSE, axis_side = NULL, |
14 | 15 |
axis_gp = gpar(fontsize = 8))} |
15 | 16 |
\arguments{ |
16 | 17 |
|
17 | 18 |
\item{x}{a matrix or a list. If \code{x} is a matrix and if \code{which} is \code{column}, statistics for boxplotis calculated by columns, if \code{which} is \code{row}, the calculation is by rows.} |
18 | 19 |
\item{which}{is the annotation a column annotation or a row annotation?} |
20 |
+ \item{border}{whether show border of the annotation compoment} |
|
19 | 21 |
\item{gp}{graphic parameters} |
20 | 22 |
\item{pch}{point type} |
21 | 23 |
\item{size}{point size} |
... | ... |
@@ -38,6 +40,7 @@ Zuguang Gu <z.gu@dkfz.de> |
38 | 40 |
|
39 | 41 |
|
40 | 42 |
|
43 |
+ |
|
41 | 44 |
mat = matrix(rnorm(32), nrow = 4) |
42 | 45 |
f = anno_boxplot(mat) |
43 | 46 |
grid.newpage(); f(1:8) |
... | ... |
@@ -9,13 +9,14 @@ Using points as annotation |
9 | 9 |
|
10 | 10 |
} |
11 | 11 |
\usage{ |
12 |
-anno_points(x, which = c("column", "row"), gp = gpar(), pch = 16, |
|
12 |
+anno_points(x, which = c("column", "row"), border = TRUE, gp = gpar(), pch = 16, |
|
13 | 13 |
size = unit(2, "mm"), axis = FALSE, axis_side = NULL, |
14 | 14 |
axis_gp = gpar(fontsize = 8), ...)} |
15 | 15 |
\arguments{ |
16 | 16 |
|
17 | 17 |
\item{x}{a vector of numeric values.} |
18 | 18 |
\item{which}{is the annotation a column annotation or a row annotation?} |
19 |
+ \item{border}{whether show border of the annotation compoment} |
|
19 | 20 |
\item{gp}{graphic parameters.} |
20 | 21 |
\item{pch}{point type.} |
21 | 22 |
\item{size}{point size.} |
... | ... |
@@ -39,5 +40,6 @@ Zuguang Gu <z.gu@dkfz.de> |
39 | 40 |
|
40 | 41 |
|
41 | 42 |
|
43 |
+ |
|
42 | 44 |
f = anno_points(rnorm(10)) |
43 | 45 |
grid.newpage(); f(1:10)} |
... | ... |
@@ -26,6 +26,7 @@ This function is only for internal use. |
26 | 26 |
|
27 | 27 |
|
28 | 28 |
|
29 |
+ |
|
29 | 30 |
This function is only for internal use.} |
30 | 31 |
\value{ |
31 | 32 |
A \code{\link[grid]{unit}} object. |
... | ... |
@@ -42,4 +43,5 @@ Zuguang Gu <z.gu@dkfz.de> |
42 | 43 |
|
43 | 44 |
|
44 | 45 |
|
46 |
+ |
|
45 | 47 |
# no example for this internal method} |
... | ... |
@@ -83,3 +83,18 @@ for colors for continous values. |
83 | 83 |
Heatmap(mat, col = topo.colors(50), row_hclust_width = unit(2, "cm"), |
84 | 84 |
column_hclust_height = unit(2, "cm")) |
85 | 85 |
``` |
86 |
+ |
|
87 |
+``` |
|
88 |
+mat = readRDS(paste0(system.files("extdata", package = "ComplexHeatmap"), "/measles.RData")) |
|
89 |
+ha = HeatmapAnnotation(dist = anno_barplot(colSums(mat))) |
|
90 |
+Heatmap(mat, name = "mat", col = colorRamp2(c(0, 800, 1000, 127000), c("white", "cornflowerblue", "yellow", "red")), |
|
91 |
+ cluster_columns = FALSE, show_row_hclust = FALSE, rect_gp = gpar(col= "white"), |
|
92 |
+ column_title = 'Measles cases in US states 1930-2001\nVaccine introduced 1961\n(data from Project Tycho)', |
|
93 |
+ top_annotation = ha, top_annotation_height = unit(4, "cm")) |
|
94 |
+ |
|
95 |
+decorate_heatmap_body("mat", { |
|
96 |
+ i = which(yd$year == 1961) |
|
97 |
+ x = i/ncol(mat) |
|
98 |
+ grid.lines(c(x, x), c(0, 1), gp = gpar(lty = 2, lwd = 2)) |
|
99 |
+}) |
|
100 |
+``` |
|
86 | 101 |
\ No newline at end of file |