1d4d6914 |
##' add horizontal align lines
##'
|
0d9e240e |
##'
|
1d4d6914 |
##' @title geom_aline
##' @param mapping aes mapping
##' @param linetype line type
##' @param size line size
##' @param ... additional parameter
##' @return aline layer
##' @export
##' @author Yu Guangchuang
geom_aline <- function(mapping=NULL, linetype="dotted", size=1, ...) {
x <- y <- isTip <- NULL
|
6c9cd355 |
dot_mapping <- aes(xend=x+diff(range(x))/200, x=max(x), yend=y, subset=isTip)
|
1d4d6914 |
if (!is.null(mapping)) {
dot_mapping <- modifyList(dot_mapping, mapping)
}
|
0d9e240e |
|
6c9cd355 |
geom_segment2(dot_mapping,
linetype=linetype,
size=size, ...)
|
1d4d6914 |
}
|
6c9cd355 |
##' geom_segment2 support aes(subset) via setup_data
##'
|
0d9e240e |
##'
|
6c9cd355 |
##' @title geom_segment2
|
0d9e240e |
##' @param mapping aes mapping
|
6c9cd355 |
##' @param data data
##' @param position position
##' @param arrow arrow
##' @param lineend lineend
##' @param na.rm logical
##' @param show.legend logical
##' @param inherit.aes logical
##' @param ... additional parameter
##' @importFrom ggplot2 layer
##' @export
##' @seealso
##' \link[ggplot2]{geom_segment}
##' @return add segment layer
##' @author Guangchuang Yu
|
0d9e240e |
geom_segment2 <- function(mapping = NULL, data = NULL,
|
6c9cd355 |
position = "identity", arrow = NULL, lineend = "butt",
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
...) {
|
e4ea056a |
default_aes <- aes_(node=~node)
if (is.null(mapping)) {
mapping <- default_aes
} else {
mapping <- modifyList(mapping, default_aes)
}
|
0d9e240e |
|
e4ea056a |
layer(
data = data,
mapping = mapping,
|
7d9641c6 |
stat = StatTreeData,
|
e4ea056a |
geom = GeomSegmentGGtree,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
arrow = arrow,
lineend = lineend,
na.rm = na.rm,
...
|
bedefde1 |
),
|
0d9e240e |
check.aes = FALSE
|
6c9cd355 |
)
}
##' @importFrom ggplot2 GeomSegment
##' @importFrom ggplot2 draw_key_path
GeomSegmentGGtree <- ggproto("GeomSegmentGGtree", GeomSegment,
|
e4ea056a |
setup_data = function(data, params) {
if (is.null(data$subset))
return(data)
|
275491b1 |
data[which(data$subset),]
|
e4ea056a |
},
|
0d9e240e |
|
e4ea056a |
draw_panel = function(data, panel_scales, coord, arrow = NULL,
lineend = "butt", na.rm = FALSE) {
|
0d9e240e |
|
e4ea056a |
GeomSegment$draw_panel(data, panel_scales, coord, arrow,
lineend, na.rm)
},
|
0d9e240e |
|
e4ea056a |
required_aes = c("x", "y", "xend", "yend"),
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),
|
0d9e240e |
|
e4ea056a |
draw_key = draw_key_path
)
|
6c9cd355 |
|
e4ea056a |
|