3

I was running the example here, and noticed that the horizontal arrow connecting the Total to the Ineligible boxGrobs doesn't always touch the left-edge of the the Ineligible boxGrob.

It seems to depend on the width of the viewing window in RStudio. This does not seem to be the case for the vertical arrow, which always seem to perfectly connect to the top of the correct boxGrob.

Is there a way to force the arrow to touch the side of the box and not go any further? I am trying to save the output to a pdf, and by default it seems to use a wider plotting window so all of my horizontal arrows don't align with the correct boxes.

Narrow plotting window:

image

Wide plotting window:

image

I have tried manually creating a viewport with a wider area, but that didn't change anything in the pdf:

Code:

library(grid)
library(Gmisc)

vp <- grid::viewport(x = 10, y = 10, clip = 'on', xscale = c(0, 10), 
                     yscale = c(0, 10), default.units = 'inch') 
grid::pushViewport(vp)

leftx  <- .25
midx   <- .5
rightx <- .75
width  <- .4
gp <- gpar(fill = "lightgrey")

# add box/connectors to the plot
(total <- boxGrob("Total\n N = NNN", 
 x=midx, y=.9, box_gp = gp, width = width))
(rando <- boxGrob("Randomized\n N = NNN", 
 x=midx, y=.75, box_gp = gp, width = width))

connectGrob(total, rando, "v")

(inel <- boxGrob("Ineligible\n N = NNN", 
 x=rightx, y=.825, box_gp = gp, width = .25, height = .05))

connectGrob(total, inel, "-")
morgan121
  • 2,213
  • 1
  • 15
  • 33

1 Answers1

1

For the time being, this problem can be solved using absolute unit.

Example code:

(inel <- boxGrob("Ineligible\n N = NNN", 
                 x=rightx, y=.825, box_gp = gp, width = unit(2, "inch"), height = .05))
cuttlefish44
  • 6,586
  • 2
  • 17
  • 34
  • awesome, works for me thanks :) You say 'for the time being'. Is this a known issue? – morgan121 Sep 25 '19 at 05:35
  • 1
    The reason of 'for the time being' is that I think maybe you like relative scale (and my English is poor, excuse me). If you're satisfied by absolute scale, please ignore the sentence. I'm glad you're happy. – cuttlefish44 Sep 25 '19 at 09:53