Skip to content

Commit

Permalink
Merge pull request #132 from r-causal/geom_dag_label_repel2
Browse files Browse the repository at this point in the history
add `geom_label_repel2()` and tweak overall defaults
  • Loading branch information
malcolmbarrett authored Jan 29, 2024
2 parents b6a254e + af2da6d commit 969ff03
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 318 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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ggdag (development version)

* Introduced new functions `aes_dag()` and `geom_dag()` to simplify specification of ggplot code for most DAGs. Also refactored most quick plots to use these functions (#121)
* Added new function `geom_label_repel2()` for more opinionated repelled labels that often look better on DAGs (#132)

# ggdag 0.2.11

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
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ generalizability
geoms
ggplot
ggraph
ggrepel
glioma
graphviz
grey
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 969ff03

Please sign in to comment.