From b462402622aac97c308c1b99a1feeb84c02391bf Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Sun, 1 Nov 2020 15:00:48 +0900 Subject: [PATCH] Handle descrete scale on calculating label positions (#161) Fix #160 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/label.R | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 139255c..7851109 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Depends: ggplot2 (>= 3.0.0), R (>= 3.2.0) Imports: - dplyr (> 0.7.0), + dplyr (>= 1.0.0), ggrepel, lifecycle, purrr, diff --git a/NEWS.md b/NEWS.md index d6edd65..06ef979 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # gghighlight (development version) +* `gghighlight()` now can add labels on discrete scales (#160). + # gghighlight 0.3.0 ## Breaking changes diff --git a/R/label.R b/R/label.R index 5bba78f..c8b5934 100644 --- a/R/label.R +++ b/R/label.R @@ -89,8 +89,8 @@ generate_label_for_line <- function(layer, label_key, label_params, max_labels) inform("Too many data series, skip labeling") return(list()) } - - rightmost_points <- dplyr::filter(data, !!x_key == max(!!x_key)) + + rightmost_points <- dplyr::slice_max(data, !!x_key) # max value can appear multiple times, so ensure only one row per group rightmost_points <- dplyr::slice(rightmost_points, 1) @@ -105,7 +105,7 @@ generate_label_for_point <- function(layer, label_key, label_params, max_labels) inform("Too many data points, skip labeling") return(list()) } - + mapping <- layer$mapping mapping$label <- label_key