Skip to content
This repository
Browse code

guide_axis: fix axis justification

  • Loading branch information...
commit b8056802214c2d2716b48de9007a5020b292b7da 1 parent 71c1c16
Winston Chang wch authored

Showing 2 changed files with 12 additions and 18 deletions. Show diff stats Hide diff stats

  1. +3 2 R/grob-absolute.r
  2. +9 16 R/guides-axis.r
5 R/grob-absolute.r
@@ -10,12 +10,13 @@
10 10 #' @S3method grobY absoluteGrob
11 11 #' @S3method grid.draw absoluteGrob
12 12 #' @keywords internal
13   -absoluteGrob <- function(grob, width = NULL, height = NULL, xmin = NULL, ymin = NULL) {
  13 +absoluteGrob <- function(grob, width = NULL, height = NULL,
  14 + xmin = NULL, ymin = NULL, vp = NULL) {
14 15 gTree(
15 16 children = grob,
16 17 width = width, height = height,
17 18 xmin = xmin, ymin = ymin,
18   - cl="absoluteGrob"
  19 + vp = vp, cl="absoluteGrob"
19 20 )
20 21 }
21 22
25 R/guides-axis.r
@@ -101,25 +101,18 @@ guide_axis <- function(at, labels, position="right", theme) {
101 101 height = one)
102 102 )
103 103
104   - # Create the gtable and wrap it in a gtable_gTree for justification
105   - gtt <- switch(position,
106   - top = gtable_gTree(gt,
107   - vp = viewport(y = 0, just = "bottom", height = gtable_height(gt))
108   - ),
109   - bottom = gtable_gTree(gt,
110   - vp = viewport(y = 1, just = "top", height = gtable_height(gt))
111   - ),
112   - right = gtable_gTree(gt,
113   - vp = viewport(x = 0, just = "left", width = gtable_width(gt))
114   - ),
115   - left = gtable_gTree(gt,
116   - vp = viewport(x = 1, just = "right", width = gtable_width(gt))
117   - )
  104 + # Viewport for justifying the axis grob
  105 + justvp <- switch(position,
  106 + top = viewport(y = 0, just = "bottom", height = gtable_height(gt)),
  107 + bottom = viewport(y = 1, just = "top", height = gtable_height(gt)),
  108 + right = viewport(x = 0, just = "left", width = gtable_width(gt)),
  109 + left = viewport(x = 1, just = "right", width = gtable_width(gt))
118 110 )
119 111
120 112 absoluteGrob(
121   - gList(line, gtt),
  113 + gList(line, gt),
122 114 width = gtable_width(gt),
123   - height = gtable_height(gt)
  115 + height = gtable_height(gt),
  116 + vp = justvp
124 117 )
125 118 }

0 comments on commit b805680

Please sign in to comment.
Something went wrong with that request. Please try again.