Skip to content

Commit

Permalink
add geom_label_repel2() and tweak overall defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmbarrett committed Jan 29, 2024
1 parent b6a254e commit 5456f31
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 317 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export(geom_dag_edges_fan)
export(geom_dag_edges_link)
export(geom_dag_label)
export(geom_dag_label_repel)
export(geom_dag_label_repel2)
export(geom_dag_node)
export(geom_dag_point)
export(geom_dag_text)
Expand Down
31 changes: 24 additions & 7 deletions R/geom_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ geom_dag_label <- function(mapping = NULL, data = NULL,

#' Repulsive textual annotations
#'
#' These functions are minor modifications of those in the `ggrepel`
#' package. geom_dag_text_repel adds text directly to the plot.
#' geom_dag_label_repel draws a rectangle underneath the text, making it easier
#' to read. The text labels repel away from each other and away from the data
#' points.
#' These functions are minor modifications of those in the ggrepel package.
#' `geom_dag_text_repel()` adds text directly to the plot.
#' `geom_dag_label_repel()` draws a rectangle underneath the text, making it
#' easier to read. The text labels repel away from each other and away from the
#' data points. `geom_dag_label_repel2()` is a slightly stylized version of
#' geom_dag_label_repel()` that often looks better on DAGs.
#'
#' @inheritParams ggrepel::geom_text_repel
#' @inheritParams ggrepel::geom_label_repel
Expand Down Expand Up @@ -291,7 +292,7 @@ geom_dag_text_repel <- function(mapping = NULL,
data = NULL,
parse = FALSE,
...,
box.padding = 0.35,
box.padding = 1.25,
point.padding = 1.5,
segment.color = "#666666",
fontface = "bold",
Expand Down Expand Up @@ -325,6 +326,7 @@ geom_dag_text_repel <- function(mapping = NULL,
max.iter = max.iter,
nudge_x = nudge_x,
nudge_y = nudge_y,
segment.alpha = 1,
...
)
)
Expand All @@ -337,7 +339,7 @@ geom_dag_text_repel <- function(mapping = NULL,
geom_dag_label_repel <- function(mapping = NULL, data = NULL,
parse = FALSE,
...,
box.padding = grid::unit(0.35, "lines"),
box.padding = grid::unit(1.25, "lines"),
label.padding = grid::unit(0.25, "lines"),
point.padding = grid::unit(1.5, "lines"),
label.r = grid::unit(0.15, "lines"),
Expand Down Expand Up @@ -375,11 +377,26 @@ geom_dag_label_repel <- function(mapping = NULL, data = NULL,
max.iter = max.iter,
nudge_x = nudge_x,
nudge_y = nudge_y,
segment.alpha = 1,
...
)
)
}

#' @rdname repel
#' @export
geom_dag_label_repel2 <- function(mapping = NULL, data = NULL, box.padding = 2,
max.overlaps = Inf, label.size = NA, ...) {
geom_dag_label_repel(
mapping = mapping,
data = data,
box.padding = box.padding,
max.overlaps = max.overlaps,
label.size = label.size,
...
)
}

filter_direction <- function(.direction) {
function(x) {
x <- dplyr::filter(x, direction == .direction)
Expand Down
30 changes: 23 additions & 7 deletions man/repel.Rd

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

Loading

0 comments on commit 5456f31

Please sign in to comment.