... | ... |
@@ -1,30 +1,41 @@ |
1 | 1 |
##' geom_label2 support aes(subset) via setup_data |
2 | 2 |
##' |
3 |
+##' 'geom_label2' is a modified version of geom_label, with subset aesthetic supported |
|
3 | 4 |
##' |
4 | 5 |
##' @title geom_label2 |
5 |
-##' @param mapping the aesthetic mapping |
|
6 |
+##' @param mapping Set of aesthetic mappings, defaults to NULL. |
|
6 | 7 |
##' @param data A layer specific dataset - |
7 | 8 |
##' only needed if you want to override the plot defaults. |
8 |
-##' @param ... other arguments passed on to 'layer' |
|
9 |
-##' @param stat Name of stat to modify data |
|
10 |
-##' @param position The position adjustment to use for overlapping points on this layer |
|
11 |
-##' @param family sans by default, can be any supported font |
|
12 |
-##' @param parse if TRUE, the labels will be parsed as expressions |
|
13 |
-##' @param nudge_x horizontal adjustment |
|
14 |
-##' @param nudge_y vertical adjustment |
|
15 |
-##' @param label.padding Amount of padding around label. |
|
16 |
-##' @param label.r Radius of rounded corners. |
|
17 |
-##' @param label.size Size of label border, in mm |
|
18 |
-##' @param na.rm logical |
|
19 |
-##' @param show.legend logical |
|
20 |
-##' @param inherit.aes logical |
|
9 |
+##' @param ... other arguments passed on to 'layer'. |
|
10 |
+##' @param stat Name of the stat to modify data. |
|
11 |
+##' @param position The position adjustment to use for overlapping points on this layer. |
|
12 |
+##' @param family "sans" by default, can be any supported font. |
|
13 |
+##' @param parse if 'TRUE', the labels will be parsed as expressions, defaults to 'FALSE'. |
|
14 |
+##' @param nudge_x adjust the horizontal position of the labels. |
|
15 |
+##' @param nudge_y adjust the vertical position of the labels. |
|
16 |
+##' @param label.padding Amount of padding around label, defaults to 'unit(0.25, "lines")'. |
|
17 |
+##' @param label.r Use to set the radius of rounded corners of the label, defaults to 'unit(0.15, "lines")'. |
|
18 |
+##' @param label.size Size of label border, in mm, defaults to 0.25. |
|
19 |
+##' @param na.rm If "FALSE" (default), missing values are removed with a warning. If "TRUE", missing values are silently removed, logical. |
|
20 |
+##' @param show.legend Whether to show legend, logical, defaults to "NA". |
|
21 |
+##' @param inherit.aes Whether to inherit aesthetic mappings, logical, defaults to "TRUE". |
|
21 | 22 |
##' @return label layer |
22 | 23 |
##' @importFrom ggplot2 layer |
23 | 24 |
##' @importFrom ggplot2 position_nudge |
25 |
+##' @examples |
|
26 |
+##' library(ggtree) |
|
27 |
+##' set.seed(123) |
|
28 |
+##' tr<- rtree(15) |
|
29 |
+##' x <- ggtree(tr) |
|
30 |
+##' x + geom_label2(aes(label = node, subset = isTip == FALSE)) |
|
24 | 31 |
##' @export |
25 | 32 |
##' @seealso |
26 | 33 |
##' [geom_label][ggplot2::geom_label] |
27 | 34 |
##' @author Guangchuang Yu |
35 |
+##' @references |
|
36 |
+##' For more detailed demonstration of this function, please refer to chapter A.4.5 of |
|
37 |
+##' *Data Integration, Manipulation and Visualization of Phylogenetic Trees* |
|
38 |
+##' <http://yulab-smu.top/treedata-book/index.html> by Guangchuang Yu. |
|
28 | 39 |
geom_label2 <- function(mapping = NULL, data = NULL, |
29 | 40 |
..., |
30 | 41 |
stat = "identity", |
... | ... |
@@ -9,7 +9,7 @@ |
9 | 9 |
##' @param stat Name of stat to modify data |
10 | 10 |
##' @param position The position adjustment to use for overlapping points on this layer |
11 | 11 |
##' @param family sans by default, can be any supported font |
12 |
-##' @param parse if TRUE, the labels will be passd into expressions |
|
12 |
+##' @param parse if TRUE, the labels will be parsed as expressions |
|
13 | 13 |
##' @param nudge_x horizontal adjustment |
14 | 14 |
##' @param nudge_y vertical adjustment |
15 | 15 |
##' @param label.padding Amount of padding around label. |
Merge remote-tracking branch 'upstream/master'
# Conflicts:
# R/geom_cladelabel.R
# R/geom_hilight.R
... | ... |
@@ -6,6 +6,7 @@ |
6 | 6 |
##' @param data A layer specific dataset - |
7 | 7 |
##' only needed if you want to override he plot defaults. |
8 | 8 |
##' @param ... other arguments passed on to 'layer' |
9 |
+##' @param stat Name of stat to modify data |
|
9 | 10 |
##' @param position The position adjustment to use for overlapping points on this layer |
10 | 11 |
##' @param family sans by default, can be any supported font |
11 | 12 |
##' @param parse if TRUE, the labels will be passd into expressions |
... | ... |
@@ -26,6 +27,7 @@ |
26 | 27 |
##' @author Guangchuang Yu |
27 | 28 |
geom_label2 <- function(mapping = NULL, data = NULL, |
28 | 29 |
..., |
30 |
+ stat = "identity", |
|
29 | 31 |
position = "identity", |
30 | 32 |
family = "sans", |
31 | 33 |
parse = FALSE, |
... | ... |
@@ -46,7 +48,7 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
46 | 48 |
position <- position_nudge(nudge_x, nudge_y) |
47 | 49 |
} |
48 | 50 |
|
49 |
- default_aes <- aes_(node=~node) |
|
51 |
+ default_aes <- aes_() #node=~node) |
|
50 | 52 |
if (is.null(mapping)) { |
51 | 53 |
mapping <- default_aes |
52 | 54 |
} else { |
... | ... |
@@ -65,7 +67,7 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
65 | 67 |
layer( |
66 | 68 |
data = data, |
67 | 69 |
mapping = mapping, |
68 |
- stat = StatTreeData, |
|
70 |
+ stat = stat, |
|
69 | 71 |
geom = GeomLabelGGtree, |
70 | 72 |
position = position, |
71 | 73 |
show.legend = show.legend, |
... | ... |
@@ -91,24 +93,24 @@ GeomLabelGGtree <- ggproto("GeomLabelGGtree", GeomLabel, |
91 | 93 |
if (is.null(data$subset)) |
92 | 94 |
return(data) |
93 | 95 |
data[which(data$subset),] |
94 |
- }, |
|
95 |
- draw_panel = function(self, data, panel_scales, coord, parse = FALSE, |
|
96 |
- na.rm = FALSE, |
|
97 |
- label.padding = unit(0.25, "lines"), |
|
98 |
- label.r = unit(0.15, "lines"), |
|
99 |
- label.size = 0.25) { |
|
100 |
- GeomLabel$draw_panel(data, panel_scales, coord, parse, |
|
101 |
- na.rm, label.padding, label.r, label.size) |
|
102 |
- }, |
|
103 |
- required_aes = c("node", "x", "y", "label"), |
|
96 |
+ }## , |
|
97 |
+ ## draw_panel = function(self, data, panel_scales, coord, parse = FALSE, |
|
98 |
+ ## na.rm = FALSE, |
|
99 |
+ ## label.padding = unit(0.25, "lines"), |
|
100 |
+ ## label.r = unit(0.15, "lines"), |
|
101 |
+ ## label.size = 0.25) { |
|
102 |
+ ## GeomLabel$draw_panel(data, panel_scales, coord, parse, |
|
103 |
+ ## na.rm, label.padding, label.r, label.size) |
|
104 |
+ ## }, |
|
105 |
+ ## required_aes = c("x", "y", "label"), |
|
104 | 106 |
|
105 |
- default_aes = aes( |
|
106 |
- colour = "black", fill = "white", size = 3.88, angle = 0, |
|
107 |
- hjust = 0.5, vjust = 0.5, alpha = NA, family = "", fontface = 1, |
|
108 |
- lineheight = 1.2 |
|
109 |
- ), |
|
107 |
+ ## default_aes = aes( |
|
108 |
+ ## colour = "black", fill = "white", size = 3.88, angle = 0, |
|
109 |
+ ## hjust = 0.5, vjust = 0.5, alpha = NA, family = "", fontface = 1, |
|
110 |
+ ## lineheight = 1.2 |
|
111 |
+ ## ), |
|
110 | 112 |
|
111 |
- draw_key = draw_key_label |
|
113 |
+ ## draw_key = draw_key_label |
|
112 | 114 |
) |
113 | 115 |
|
114 | 116 |
|
Fixed layoutDaylight ave_change calculation.
Fixed bug in getTreeArcAngles() for cases where the branch root node and origin node are the same.
Added getNodeEuclDistances() function.
Fixed isTip() function to check if nodes has children, instead of checking of the data variable had the isTip field set.
... | ... |
@@ -4,7 +4,7 @@ |
4 | 4 |
##' @title geom_label2 |
5 | 5 |
##' @param mapping the aesthetic mapping |
6 | 6 |
##' @param data A layer specific dataset - |
7 |
-##' only needed if you want to override he plot defaults. |
|
7 |
+##' only needed if you want to override the plot defaults. |
|
8 | 8 |
##' @param ... other arguments passed on to 'layer' |
9 | 9 |
##' @param position The position adjustment to use for overlapping points on this layer |
10 | 10 |
##' @param family sans by default, can be any supported font |
... | ... |
@@ -77,8 +77,7 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
77 | 77 |
label.r = label.r, |
78 | 78 |
label.size = label.size, |
79 | 79 |
na.rm = na.rm, |
80 |
- ... |
|
81 |
- ), |
|
80 |
+ ...), |
|
82 | 81 |
check.aes = FALSE |
83 | 82 |
) |
84 | 83 |
} |
... | ... |
@@ -6,6 +6,7 @@ |
6 | 6 |
##' @param data A layer specific dataset - |
7 | 7 |
##' only needed if you want to override he plot defaults. |
8 | 8 |
##' @param ... other arguments passed on to 'layer' |
9 |
+##' @param position The position adjustment to use for overlapping points on this layer |
|
9 | 10 |
##' @param family sans by default, can be any supported font |
10 | 11 |
##' @param parse if TRUE, the labels will be passd into expressions |
11 | 12 |
##' @param nudge_x horizontal adjustment |
... | ... |
@@ -25,6 +26,7 @@ |
25 | 26 |
##' @author Guangchuang Yu |
26 | 27 |
geom_label2 <- function(mapping = NULL, data = NULL, |
27 | 28 |
..., |
29 |
+ position = "identity", |
|
28 | 30 |
family = "sans", |
29 | 31 |
parse = FALSE, |
30 | 32 |
nudge_x = 0, |
... | ... |
@@ -36,8 +38,6 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
36 | 38 |
show.legend = NA, |
37 | 39 |
inherit.aes = TRUE) { |
38 | 40 |
|
39 |
- position = "identity" |
|
40 |
- |
|
41 | 41 |
if (!missing(nudge_x) || !missing(nudge_y)) { |
42 | 42 |
if (!missing(position)) { |
43 | 43 |
stop("Specify either `position` or `nudge_x`/`nudge_y`", call. = FALSE) |
... | ... |
@@ -1,7 +1,7 @@ |
1 |
-##' geom_text2 support aes(subset) via setup_data |
|
1 |
+##' geom_label2 support aes(subset) via setup_data |
|
2 | 2 |
##' |
3 | 3 |
##' |
4 |
-##' @title geom_text2 |
|
4 |
+##' @title geom_label2 |
|
5 | 5 |
##' @param mapping the aesthetic mapping |
6 | 6 |
##' @param data A layer specific dataset - |
7 | 7 |
##' only needed if you want to override he plot defaults. |
... | ... |
@@ -6,6 +6,7 @@ |
6 | 6 |
##' @param data A layer specific dataset - |
7 | 7 |
##' only needed if you want to override he plot defaults. |
8 | 8 |
##' @param ... other arguments passed on to 'layer' |
9 |
+##' @param family sans by default, can be any supported font |
|
9 | 10 |
##' @param parse if TRUE, the labels will be passd into expressions |
10 | 11 |
##' @param nudge_x horizontal adjustment |
11 | 12 |
##' @param nudge_y vertical adjustment |
... | ... |
@@ -24,6 +25,7 @@ |
24 | 25 |
##' @author Guangchuang Yu |
25 | 26 |
geom_label2 <- function(mapping = NULL, data = NULL, |
26 | 27 |
..., |
28 |
+ family = "sans", |
|
27 | 29 |
parse = FALSE, |
28 | 30 |
nudge_x = 0, |
29 | 31 |
nudge_y = 0, |
... | ... |
@@ -51,6 +53,15 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
51 | 53 |
mapping <- modifyList(mapping, default_aes) |
52 | 54 |
} |
53 | 55 |
|
56 |
+ if (parse == "emoji") { |
|
57 |
+ label_aes <- aes_string(label=paste0("suppressMessages(emoji(", as.list(mapping)$label,"))")) |
|
58 |
+ mapping <- modifyList(mapping, label_aes) |
|
59 |
+ emoji <- get_fun_from_pkg("emojifont", "emoji") |
|
60 |
+ parse <- FALSE |
|
61 |
+ family <- "OpenSansEmoji" |
|
62 |
+ } |
|
63 |
+ |
|
64 |
+ |
|
54 | 65 |
layer( |
55 | 66 |
data = data, |
56 | 67 |
mapping = mapping, |
... | ... |
@@ -61,6 +72,7 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
61 | 72 |
inherit.aes = inherit.aes, |
62 | 73 |
params = list( |
63 | 74 |
parse = parse, |
75 |
+ family = family, |
|
64 | 76 |
label.padding = label.padding, |
65 | 77 |
label.r = label.r, |
66 | 78 |
label.size = label.size, |
... | ... |
@@ -78,7 +78,7 @@ GeomLabelGGtree <- ggproto("GeomLabelGGtree", GeomLabel, |
78 | 78 |
setup_data = function(data, params) { |
79 | 79 |
if (is.null(data$subset)) |
80 | 80 |
return(data) |
81 |
- data[data$subset,] |
|
81 |
+ data[which(data$subset),] |
|
82 | 82 |
}, |
83 | 83 |
draw_panel = function(self, data, panel_scales, coord, parse = FALSE, |
84 | 84 |
na.rm = FALSE, |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
##' geom_text2 support aes(subset) via setup_data |
2 | 2 |
##' |
3 |
-##' |
|
3 |
+##' |
|
4 | 4 |
##' @title geom_text2 |
5 | 5 |
##' @param mapping the aesthetic mapping |
6 | 6 |
##' @param data A layer specific dataset - |
... | ... |
@@ -9,7 +9,7 @@ |
9 | 9 |
##' @param parse if TRUE, the labels will be passd into expressions |
10 | 10 |
##' @param nudge_x horizontal adjustment |
11 | 11 |
##' @param nudge_y vertical adjustment |
12 |
-##' @param label.padding Amount of padding around label. |
|
12 |
+##' @param label.padding Amount of padding around label. |
|
13 | 13 |
##' @param label.r Radius of rounded corners. |
14 | 14 |
##' @param label.size Size of label border, in mm |
15 | 15 |
##' @param na.rm logical |
... | ... |
@@ -35,22 +35,22 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
35 | 35 |
inherit.aes = TRUE) { |
36 | 36 |
|
37 | 37 |
position = "identity" |
38 |
- |
|
38 |
+ |
|
39 | 39 |
if (!missing(nudge_x) || !missing(nudge_y)) { |
40 | 40 |
if (!missing(position)) { |
41 | 41 |
stop("Specify either `position` or `nudge_x`/`nudge_y`", call. = FALSE) |
42 | 42 |
} |
43 |
- |
|
43 |
+ |
|
44 | 44 |
position <- position_nudge(nudge_x, nudge_y) |
45 | 45 |
} |
46 |
- |
|
46 |
+ |
|
47 | 47 |
default_aes <- aes_(node=~node) |
48 | 48 |
if (is.null(mapping)) { |
49 | 49 |
mapping <- default_aes |
50 | 50 |
} else { |
51 | 51 |
mapping <- modifyList(mapping, default_aes) |
52 | 52 |
} |
53 |
- |
|
53 |
+ |
|
54 | 54 |
layer( |
55 | 55 |
data = data, |
56 | 56 |
mapping = mapping, |
... | ... |
@@ -67,7 +67,7 @@ geom_label2 <- function(mapping = NULL, data = NULL, |
67 | 67 |
na.rm = na.rm, |
68 | 68 |
... |
69 | 69 |
), |
70 |
- if (packageVersion('ggplot2') > '2.1.0') check.aes = FALSE |
|
70 |
+ check.aes = FALSE |
|
71 | 71 |
) |
72 | 72 |
} |
73 | 73 |
|
... | ... |
@@ -89,13 +89,13 @@ GeomLabelGGtree <- ggproto("GeomLabelGGtree", GeomLabel, |
89 | 89 |
na.rm, label.padding, label.r, label.size) |
90 | 90 |
}, |
91 | 91 |
required_aes = c("node", "x", "y", "label"), |
92 |
- |
|
92 |
+ |
|
93 | 93 |
default_aes = aes( |
94 | 94 |
colour = "black", fill = "white", size = 3.88, angle = 0, |
95 | 95 |
hjust = 0.5, vjust = 0.5, alpha = NA, family = "", fontface = 1, |
96 | 96 |
lineheight = 1.2 |
97 | 97 |
), |
98 |
- |
|
98 |
+ |
|
99 | 99 |
draw_key = draw_key_label |
100 | 100 |
) |
101 | 101 |
|
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@122173 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@122021 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@115937 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,101 @@ |
1 |
+##' geom_text2 support aes(subset) via setup_data |
|
2 |
+##' |
|
3 |
+##' |
|
4 |
+##' @title geom_text2 |
|
5 |
+##' @param mapping the aesthetic mapping |
|
6 |
+##' @param data A layer specific dataset - |
|
7 |
+##' only needed if you want to override he plot defaults. |
|
8 |
+##' @param ... other arguments passed on to 'layer' |
|
9 |
+##' @param parse if TRUE, the labels will be passd into expressions |
|
10 |
+##' @param nudge_x horizontal adjustment |
|
11 |
+##' @param nudge_y vertical adjustment |
|
12 |
+##' @param label.padding Amount of padding around label. |
|
13 |
+##' @param label.r Radius of rounded corners. |
|
14 |
+##' @param label.size Size of label border, in mm |
|
15 |
+##' @param na.rm logical |
|
16 |
+##' @param show.legend logical |
|
17 |
+##' @param inherit.aes logical |
|
18 |
+##' @return label layer |
|
19 |
+##' @importFrom ggplot2 layer |
|
20 |
+##' @importFrom ggplot2 position_nudge |
|
21 |
+##' @export |
|
22 |
+##' @seealso |
|
23 |
+##' \link[ggplot2]{geom_label} |
|
24 |
+##' @author Guangchuang Yu |
|
25 |
+geom_label2 <- function(mapping = NULL, data = NULL, |
|
26 |
+ ..., |
|
27 |
+ parse = FALSE, |
|
28 |
+ nudge_x = 0, |
|
29 |
+ nudge_y = 0, |
|
30 |
+ label.padding = unit(0.25, "lines"), |
|
31 |
+ label.r = unit(0.15, "lines"), |
|
32 |
+ label.size = 0.25, |
|
33 |
+ na.rm = TRUE, |
|
34 |
+ show.legend = NA, |
|
35 |
+ inherit.aes = TRUE) { |
|
36 |
+ |
|
37 |
+ position = "identity" |
|
38 |
+ |
|
39 |
+ if (!missing(nudge_x) || !missing(nudge_y)) { |
|
40 |
+ if (!missing(position)) { |
|
41 |
+ stop("Specify either `position` or `nudge_x`/`nudge_y`", call. = FALSE) |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ position <- position_nudge(nudge_x, nudge_y) |
|
45 |
+ } |
|
46 |
+ |
|
47 |
+ default_aes <- aes_(node=~node) |
|
48 |
+ if (is.null(mapping)) { |
|
49 |
+ mapping <- default_aes |
|
50 |
+ } else { |
|
51 |
+ mapping <- modifyList(mapping, default_aes) |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ layer( |
|
55 |
+ data = data, |
|
56 |
+ mapping = mapping, |
|
57 |
+ stat = StatTreeData, |
|
58 |
+ geom = GeomLabelGGtree, |
|
59 |
+ position = position, |
|
60 |
+ show.legend = show.legend, |
|
61 |
+ inherit.aes = inherit.aes, |
|
62 |
+ params = list( |
|
63 |
+ parse = parse, |
|
64 |
+ label.padding = label.padding, |
|
65 |
+ label.r = label.r, |
|
66 |
+ label.size = label.size, |
|
67 |
+ na.rm = na.rm, |
|
68 |
+ ... |
|
69 |
+ ) |
|
70 |
+ ) |
|
71 |
+} |
|
72 |
+ |
|
73 |
+ |
|
74 |
+ |
|
75 |
+##' @importFrom ggplot2 GeomLabel |
|
76 |
+GeomLabelGGtree <- ggproto("GeomLabelGGtree", GeomLabel, |
|
77 |
+ setup_data = function(data, params) { |
|
78 |
+ if (is.null(data$subset)) |
|
79 |
+ return(data) |
|
80 |
+ data[data$subset,] |
|
81 |
+ }, |
|
82 |
+ draw_panel = function(self, data, panel_scales, coord, parse = FALSE, |
|
83 |
+ na.rm = FALSE, |
|
84 |
+ label.padding = unit(0.25, "lines"), |
|
85 |
+ label.r = unit(0.15, "lines"), |
|
86 |
+ label.size = 0.25) { |
|
87 |
+ GeomLabel$draw_panel(data, panel_scales, coord, parse, |
|
88 |
+ na.rm, label.padding, label.r, label.size) |
|
89 |
+ }, |
|
90 |
+ required_aes = c("node", "x", "y", "label"), |
|
91 |
+ |
|
92 |
+ default_aes = aes( |
|
93 |
+ colour = "black", fill = "white", size = 3.88, angle = 0, |
|
94 |
+ hjust = 0.5, vjust = 0.5, alpha = NA, family = "", fontface = 1, |
|
95 |
+ lineheight = 1.2 |
|
96 |
+ ), |
|
97 |
+ |
|
98 |
+ draw_key = draw_key_label |
|
99 |
+ ) |
|
100 |
+ |
|
101 |
+ |