Skip to content

Commit

Permalink
Handle descrete scale on calculating label positions (#161)
Browse files Browse the repository at this point in the history
Fix #160
  • Loading branch information
yutannihilation authored Nov 1, 2020
1 parent 8c78565 commit b462402
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gghighlight (development version)

* `gghighlight()` now can add labels on discrete scales (#160).

# gghighlight 0.3.0

## Breaking changes
Expand Down
6 changes: 3 additions & 3 deletions R/label.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down

0 comments on commit b462402

Please sign in to comment.