Skip to content

Commit

Permalink
Better vertical line exntension. #67
Browse files Browse the repository at this point in the history
  • Loading branch information
adayim committed Sep 9, 2024
1 parent 670808f commit 863b012
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 18 deletions.
6 changes: 4 additions & 2 deletions R/forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ forest <- function(data,
vert_line(x = ref_line[idx],
gp = theme$refline,
xlim = xlim[[idx]],
x_trans = x_trans[idx]),
x_trans = x_trans[idx],
nrow = nrow(data)),
t = 2,
l = j,
b = tot_row, r = j,
Expand All @@ -531,7 +532,8 @@ forest <- function(data,
vert_line(x = vert_line[[idx]],
gp = theme$vertline,
xlim = xlim[[idx]],
x_trans = x_trans[idx]),
x_trans = x_trans[idx],
nrow = nrow(data)),
t = 2,
l = j,
b = tot_row, r = j,
Expand Down
9 changes: 6 additions & 3 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ get_wh <- function(plot, unit = c("in", "cm", "mm")){


# Add vertical line
vert_line <- function(x, gp = grid::gpar(), xlim, x_trans = "none"){
vert_line <- function(x, gp = grid::gpar(), xlim, x_trans = "none", nrow = 10){

if(x_trans != "none")
x <- xscale(x, scale = x_trans)

# Multiplyer
denom <- max(c(nrow, 10))

out_indx <- x > max(xlim) | x < min(xlim)
if(all(out_indx)){
return(nullGrob())
}else{
segmentsGrob(x0 = unit(x[!out_indx],"native"),
x1 = unit(x[!out_indx],"native"),
y0 = unit(0,"npc"),
y1 = unit(1,"npc"),
y0 = unit(0,"npc") + unit(0.1,"npc")/denom,
y1 = unit(1,"npc") - unit(0.1,"npc")/denom,
gp = gp,
vp = viewport(xscale = xlim))
}
Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/forest/edit-plot-with-theme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/forest/insert-text-vector.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/forest/multiple-columns.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/forest/simple-forest-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/forest/summary-ci.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 863b012

Please sign in to comment.