Skip to content

Commit

Permalink
Merge pull request #29 from jiho/segment_color
Browse files Browse the repository at this point in the history
Make the segment the same color as the text
  • Loading branch information
slowkow committed Mar 15, 2016
2 parents 86174a8 + 0db788e commit 847b714
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
19 changes: 10 additions & 9 deletions R/geom-text-repel.R
Expand Up @@ -67,9 +67,9 @@
#' \code{unit(0.25, "lines")}.
#' @param point.padding Amount of padding around labeled point. Defaults to
#' \code{unit(0, "lines")}.
#' @param segment.color Color of the line segment connecting the data point to
#' the text labe. Defaults to \code{#666666}.
#' @param segment.size Width of segment, in mm.
#' @param segment.size Width of line segment connecting the data point to
#' the text label, in mm.
#' @param segment.alpha Transparency of the segment, in \code{[0,1]}. Makes segments half transparent by default.
#' @param arrow specification for arrow heads, as created by \code{\link[grid]{arrow}}
#' @param force Force of repulsion between overlapping text labels. Defaults
#' to 1.
Expand Down Expand Up @@ -124,8 +124,8 @@ geom_text_repel <- function(
...,
box.padding = unit(0.25, "lines"),
point.padding = unit(1e-6, "lines"),
segment.color = "#666666",
segment.size = 0.5,
segment.alpha = 0.5,
arrow = NULL,
force = 1,
max.iter = 2000,
Expand All @@ -148,8 +148,8 @@ geom_text_repel <- function(
na.rm = na.rm,
box.padding = box.padding,
point.padding = point.padding,
segment.color = segment.color,
segment.size = segment.size,
segment.alpha = segment.alpha,
arrow = arrow,
force = force,
max.iter = max.iter,
Expand All @@ -170,7 +170,7 @@ GeomTextRepel <- ggproto("GeomTextRepel", Geom,

default_aes = aes(
colour = "black", size = 3.88, angle = 0,
alpha = NA, family = "", fontface = 1, lineheight = 1.2
alpha = 1, family = "", fontface = 1, lineheight = 1.2
),

draw_panel = function(
Expand All @@ -179,8 +179,8 @@ GeomTextRepel <- ggproto("GeomTextRepel", Geom,
na.rm = FALSE,
box.padding = unit(0.25, "lines"),
point.padding = unit(1e-6, "lines"),
segment.color = "#666666",
segment.size = 0.5,
segment.alpha = 0.5,
arrow = NULL,
force = 1,
max.iter = 2000,
Expand Down Expand Up @@ -218,8 +218,8 @@ GeomTextRepel <- ggproto("GeomTextRepel", Geom,
nudges = nudges,
box.padding = box.padding,
point.padding = point.padding,
segment.color = segment.color,
segment.size = segment.size,
segment.alpha = segment.alpha,
arrow = arrow,
force = force,
max.iter = max.iter,
Expand Down Expand Up @@ -282,6 +282,7 @@ makeContent.textrepeltree <- function(x) {

grobs <- lapply(1:nrow(x$data), function(i) {
row <- x$data[i, , drop = FALSE]
# browser()
textRepelGrob(
x$lab[i],
x = unit(repel$x[i], "native"),
Expand All @@ -298,7 +299,7 @@ makeContent.textrepeltree <- function(x) {
lineheight = row$lineheight
),
segment.gp = gpar(
col = scales::alpha(x$segment.color, row$alpha),
col = scales::alpha(row$colour, row$alpha * x$segment.alpha),
lwd = x$segment.size * .pt
),
arrow = x$arrow
Expand Down
12 changes: 6 additions & 6 deletions man/geom_text_repel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 847b714

Please sign in to comment.