Browse code

column_title_rot can be any degree value

Zuguang Gu authored on 31/05/2022 09:48:27
Showing 13 changed files

... ...
@@ -1,3 +1,9 @@
1
+CHANGES in VERSION 2.13.1
2
+
3
+* `column_title_rot` can be set with any degree value.
4
+
5
+========================
6
+
1 7
 CHANGES in VERSION 2.11.2
2 8
 
3 9
 * discrete color mapping: when heatmap_param_list$at is set, it is reduced accordingly 
... ...
@@ -1,32 +1,32 @@
1
+setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
2
+setGeneric('draw', function(object, ...) standardGeneric('draw'))
3
+setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
1 4
 setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
5
+setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
6
+setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
2 7
 setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
3
-setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
4
-setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
8
+setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
9
+setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
5 10
 setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
6
-setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
11
+setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
7 12
 setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
8
-setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
9
-setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
10
-setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
11
-setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
12
-setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
13
-setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
14
-setGeneric('attach_annotation', function(object, ...) standardGeneric('attach_annotation'))
13
+setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
14
+setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
15
+setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
16
+setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
15 17
 setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
16
-setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
17
-setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
18
+setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
19
+setGeneric('attach_annotation', function(object, ...) standardGeneric('attach_annotation'))
20
+setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
21
+setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
22
+setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
18 23
 setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
24
+setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
25
+setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
19 26
 setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
20
-setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
21
-setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
22
-setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
23
-setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
24
-setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
25
-setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
26
-setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
27
-setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
28
-setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
29
-setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
30 27
 setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
28
+setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
31 29
 setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
32
-setGeneric('draw', function(object, ...) standardGeneric('draw'))
30
+setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
31
+setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
32
+setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
... ...
@@ -102,11 +102,11 @@ Heatmap = setClass("Heatmap",
102 102
 # -row_title Title on the row.
103 103
 # -row_title_side Will the title be put on the left or right of the heatmap?
104 104
 # -row_title_gp Graphic parameters for row title.
105
-# -row_title_rot Rotation of row title. Only 0, 90, 270 are allowed to set.
105
+# -row_title_rot Rotation of row title.
106 106
 # -column_title Title on the column.
107 107
 # -column_title_side Will the title be put on the top or bottom of the heatmap?
108 108
 # -column_title_gp Graphic parameters for column title.
109
-# -column_title_rot Rotation of column titles. Only 0, 90, 270 are allowed to set.
109
+# -column_title_rot Rotation of column titles.
110 110
 # -cluster_rows If the value is a logical, it controls whether to make cluster on rows. The value can also
111 111
 #               be a `stats::hclust` or a `stats::dendrogram` which already contains clustering.
112 112
 #               Check https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#clustering .
... ...
@@ -99,18 +99,10 @@ setMethod(f = "make_layout",
99 99
     }
100 100
     if(length(column_title) > 0) {
101 101
         if(column_title_side == "top") {
102
-            if(column_title_rot %in% c(0, 180)) {
103
-                object@layout$layout_size$column_title_top_height = grobHeight(textGrob(column_title, gp = column_title_gp)) + sum(title_padding)
104
-            } else {
105
-                object@layout$layout_size$column_title_top_height = grobWidth(textGrob(column_title, gp = column_title_gp)) + sum(title_padding)
106
-            }
102
+            object@layout$layout_size$column_title_top_height = grobHeight(textGrob(column_title, gp = column_title_gp, rot = column_title_rot)) + sum(title_padding)
107 103
             object@layout$layout_index = rbind(object@layout$layout_index, column_title_top = heatmap_layout_index("column_title_top"))
108 104
         } else {
109
-            if(column_title_rot %in% c(0, 180)) {
110
-                object@layout$layout_size$column_title_bottom_height = grobHeight(textGrob(column_title, gp = column_title_gp)) + sum(title_padding)
111
-            } else {
112
-                object@layout$layout_size$column_title_bottom_height = grobWidth(textGrob(column_title, gp = column_title_gp)) + sum(title_padding)
113
-            }
105
+            object@layout$layout_size$column_title_bottom_height = grobHeight(textGrob(column_title, gp = column_title_gp, rot = column_title_rot)) + sum(title_padding)
114 106
             object@layout$layout_index = rbind(object@layout$layout_index, column_title_bottom = heatmap_layout_index("column_title_bottom"))
115 107
         }
116 108
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
... ...
@@ -139,18 +131,10 @@ setMethod(f = "make_layout",
139 131
     }
140 132
     if(length(row_title) > 0) {
141 133
         if(row_title_side == "left") {
142
-            if(row_title_rot %in% c(0, 180)) {
143
-                object@layout$layout_size$row_title_left_width = max_text_width(row_title, gp = row_title_gp) + sum(title_padding)
144
-            } else {
145
-                object@layout$layout_size$row_title_left_width = max_text_height(row_title, gp = row_title_gp) + sum(title_padding)
146
-            }
134
+            object@layout$layout_size$row_title_left_width = max_text_width(row_title, gp = row_title_gp, rot = row_title_rot) + sum(title_padding)
147 135
             object@layout$layout_index = rbind(object@layout$layout_index, row_title_left = heatmap_layout_index("row_title_left"))
148 136
         } else {
149
-            if(row_title_rot %in% c(0, 180)) {
150
-                object@layout$layout_size$row_title_right_width = max_text_width(row_title, gp = row_title_gp) + sum(title_padding)
151
-            } else {
152
-                object@layout$layout_size$row_title_right_width = max_text_height(row_title, gp = row_title_gp) + sum(title_padding)
153
-            }
137
+            object@layout$layout_size$row_title_right_width = max_text_width(row_title, gp = row_title_gp, rot = row_title_rot) + sum(title_padding)
154 138
             object@layout$layout_index = rbind(object@layout$layout_index, row_title_right = heatmap_layout_index("row_title_right"))
155 139
         }
156 140
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
... ...
@@ -286,10 +286,10 @@ subset_gp = function(gp, i) {
286 286
 
287 287
 
288 288
 get_text_just = function(rot, side) {
289
-    rot = rot %% 360
290
-    if(! rot %in% c(0, 90, 270)) {
291
-        stop_wrap("Only support horizontal or vertical rotations for text.\n")
292
-    }
289
+    rot = rot %% 180
290
+    # if(! rot %in% c(0, 90, 270)) {
291
+    #     stop_wrap("Only support horizontal or vertical rotations for text.\n")
292
+    # }
293 293
     if(side == "left") {
294 294
         if(rot == 0) {
295 295
             return(c(1, 0.5))
... ...
@@ -299,27 +299,27 @@ get_text_just = function(rot, side) {
299 299
             return(c(0.5, 1))
300 300
         }
301 301
     } else if(side == "right") {
302
-        if(rot == 0) {
302
+        if(rot >= 0 && rot < 90) {
303 303
             return(c(0, 0.5))
304 304
         } else if(rot == 90) {
305 305
             return(c(0.5, 1))
306
-        } else if(rot == 270) {
307
-            return(c(0.5, 0))
306
+        } else if(rot > 90 && rot < 180) {
307
+            return(c(0, 0.5))
308 308
         }
309 309
     } else if(side == "top") {
310 310
         if(rot == 0) {
311 311
             return(c(0.5, 0))
312
-        } else if(rot == 90) {
312
+        } else if(rot > 0 && rot <= 90) {
313 313
             return(c(0, 0.5))
314
-        } else if(rot == 270) {
314
+        } else if(rot > 90 && rot <= 180) {
315 315
             return(c(1, 0.5))
316 316
         }
317 317
     } else if(side == "bottom") {
318 318
         if(rot == 0) {
319 319
             return(c(0.5, 1))
320
-        } else if(rot == 90) {
320
+        } else if(rot > 0 && rot <= 90) {
321 321
             return(c(1, 0.5))
322
-        } else if(rot == 270) {
322
+        } else if(rot > 90 && rot <= 180) {
323 323
             return(c(0, 0.5))
324 324
         }
325 325
     }
... ...
@@ -115,11 +115,11 @@ Heatmap(matrix, col, name,
115 115
   \item{row_title}{Title on the row.}
116 116
   \item{row_title_side}{Will the title be put on the left or right of the heatmap?}
117 117
   \item{row_title_gp}{Graphic parameters for row title.}
118
-  \item{row_title_rot}{Rotation of row title. Only 0, 90, 270 are allowed to set.}
118
+  \item{row_title_rot}{Rotation of row title.}
119 119
   \item{column_title}{Title on the column.}
120 120
   \item{column_title_side}{Will the title be put on the top or bottom of the heatmap?}
121 121
   \item{column_title_gp}{Graphic parameters for column title.}
122
-  \item{column_title_rot}{Rotation of column titles. Only 0, 90, 270 are allowed to set.}
122
+  \item{column_title_rot}{Rotation of column titles.}
123 123
   \item{cluster_rows}{If the value is a logical, it controls whether to make cluster on rows. The value can also be a \code{\link[stats]{hclust}} or a \code{\link[stats]{dendrogram}} which already contains clustering. Check \url{https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#clustering} .}
124 124
   \item{cluster_row_slices}{If rows are split into slices, whether perform clustering on the slice means?}
125 125
   \item{clustering_distance_rows}{It can be a pre-defined character which is in  ("euclidean", "maximum", "manhattan", "canberra", "binary",  "minkowski", "pearson", "spearman", "kendall"). It can also be a function. If the function has one argument, the input argument should be a matrix and  the returned value should be a \code{\link[stats]{dist}} object. If the function has two arguments, the input arguments are two vectors and the function calculates distance between these two vectors.}
... ...
@@ -10,9 +10,9 @@ Method dispatch page for \code{add_heatmap}.
10 10
 \code{add_heatmap} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{add_heatmap,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{add_heatmap,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
15 14
 \item \code{\link{add_heatmap,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15
+\item \code{\link{add_heatmap,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
16 16
 }
17 17
 }
18 18
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{column_order}.
10 10
 \code{column_order} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{column_order,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{component_width}.
10 10
 \code{component_width} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{component_width,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14 13
 \item \code{\link{component_width,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{component_width,Heatmap-method}}, \code{\link{Heatmap-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,12 +10,12 @@ Method dispatch page for \code{draw}.
10 10
 \code{draw} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
14
-\item \code{\link{draw,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
15 13
 \item \code{\link{draw,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
16 14
 \item \code{\link{draw,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
17 15
 \item \code{\link{draw,Legends-method}}, \code{\link{Legends-class}} class method
18 16
 \item \code{\link{draw,Heatmap-method}}, \code{\link{Heatmap-class}} class method
17
+\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
18
+\item \code{\link{draw,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
19 19
 }
20 20
 }
21 21
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{draw_title}.
10 10
 \code{draw_title} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{draw_title,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{draw_title,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{draw_title,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{row_dend}.
10 10
 \code{row_dend} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{row_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{row_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{row_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,11 +10,11 @@ Method dispatch page for \code{show}.
10 10
 \code{show} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
-\item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
15 13
 \item \code{\link{show,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
16 14
 \item \code{\link{show,ColorMapping-method}}, \code{\link{ColorMapping-class}} class method
17 15
 \item \code{\link{show,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
16
+\item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
17
+\item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
18 18
 \item \code{\link{show,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
19 19
 }
20 20
 }