Skip to content

Commit

Permalink
make.tiebreaker takes y value of closest x when constant
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Apr 17, 2024
1 parent c1824df commit 04cf335
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: directlabels
Maintainer: Toby Dylan Hocking <[email protected]>
Author: Toby Dylan Hocking
Version: 2024.1.21
Version: 2024.4.16
BugReports: https://github.com/tdhock/directlabels/issues
License: GPL-3
Title: Direct Labels for Multicolor Plots
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Changes in version 2024.4.16

- fix make.tiebreaker issue with constant data.

Changes in version 2024.1.21

- fix legends2hide issue with ggplot2 3.5.0.
Expand Down
9 changes: 6 additions & 3 deletions R/utility.function.R
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ make.tiebreaker <- function(x.var,tiebreak.var){
}
xvals <- xvals[order(abs(xvals-x))]
group.dfs <- split(orig,orig$groups)
m <- do.call(cbind,lapply(d$groups,function(g){
glist <- lapply(d$groups,function(g){
df <- group.dfs[[as.character(g)]]
group.x <- df[,x.var]
group.y <- df[,tiebreak.var]
Expand All @@ -957,9 +957,12 @@ make.tiebreaker <- function(x.var,tiebreak.var){
## this is required to get a good ordering in some cases.
approx(group.x, group.y, xvals, rule=2)$y
}else{
group.y
iord <- order(abs(group.x-x))
closest <- iord[1]
rep(group.y[closest], length(xvals))
}
}))
})
m <- do.call(cbind,glist)
## useful for debugging:
##print(m)
L <- lapply(1:nrow(m),function(i)m[i,])
Expand Down

0 comments on commit 04cf335

Please sign in to comment.