Skip to content

Commit 04cf335

Browse files
committed
make.tiebreaker takes y value of closest x when constant
1 parent c1824df commit 04cf335

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: directlabels
22
Maintainer: Toby Dylan Hocking <[email protected]>
33
Author: Toby Dylan Hocking
4-
Version: 2024.1.21
4+
Version: 2024.4.16
55
BugReports: https://github.com/tdhock/directlabels/issues
66
License: GPL-3
77
Title: Direct Labels for Multicolor Plots

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Changes in version 2024.4.16
2+
3+
- fix make.tiebreaker issue with constant data.
4+
15
Changes in version 2024.1.21
26

37
- fix legends2hide issue with ggplot2 3.5.0.

R/utility.function.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ make.tiebreaker <- function(x.var,tiebreak.var){
941941
}
942942
xvals <- xvals[order(abs(xvals-x))]
943943
group.dfs <- split(orig,orig$groups)
944-
m <- do.call(cbind,lapply(d$groups,function(g){
944+
glist <- lapply(d$groups,function(g){
945945
df <- group.dfs[[as.character(g)]]
946946
group.x <- df[,x.var]
947947
group.y <- df[,tiebreak.var]
@@ -957,9 +957,12 @@ make.tiebreaker <- function(x.var,tiebreak.var){
957957
## this is required to get a good ordering in some cases.
958958
approx(group.x, group.y, xvals, rule=2)$y
959959
}else{
960-
group.y
960+
iord <- order(abs(group.x-x))
961+
closest <- iord[1]
962+
rep(group.y[closest], length(xvals))
961963
}
962-
}))
964+
})
965+
m <- do.call(cbind,glist)
963966
## useful for debugging:
964967
##print(m)
965968
L <- lapply(1:nrow(m),function(i)m[i,])

0 commit comments

Comments
 (0)