Permalink
Browse files

guide_axis: fix axis justification

  • Loading branch information...
1 parent 71c1c16 commit b8056802214c2d2716b48de9007a5020b292b7da @wch wch committed Jul 18, 2012
Showing with 12 additions and 18 deletions.
  1. +3 −2 R/grob-absolute.r
  2. +9 −16 R/guides-axis.r
View
5 R/grob-absolute.r
@@ -10,12 +10,13 @@
#' @S3method grobY absoluteGrob
#' @S3method grid.draw absoluteGrob
#' @keywords internal
-absoluteGrob <- function(grob, width = NULL, height = NULL, xmin = NULL, ymin = NULL) {
+absoluteGrob <- function(grob, width = NULL, height = NULL,
+ xmin = NULL, ymin = NULL, vp = NULL) {
gTree(
children = grob,
width = width, height = height,
xmin = xmin, ymin = ymin,
- cl="absoluteGrob"
+ vp = vp, cl="absoluteGrob"
)
}
View
25 R/guides-axis.r
@@ -101,25 +101,18 @@ guide_axis <- function(at, labels, position="right", theme) {
height = one)
)
- # Create the gtable and wrap it in a gtable_gTree for justification
- gtt <- switch(position,
- top = gtable_gTree(gt,
- vp = viewport(y = 0, just = "bottom", height = gtable_height(gt))
- ),
- bottom = gtable_gTree(gt,
- vp = viewport(y = 1, just = "top", height = gtable_height(gt))
- ),
- right = gtable_gTree(gt,
- vp = viewport(x = 0, just = "left", width = gtable_width(gt))
- ),
- left = gtable_gTree(gt,
- vp = viewport(x = 1, just = "right", width = gtable_width(gt))
- )
+ # Viewport for justifying the axis grob
+ justvp <- switch(position,
+ top = viewport(y = 0, just = "bottom", height = gtable_height(gt)),
+ bottom = viewport(y = 1, just = "top", height = gtable_height(gt)),
+ right = viewport(x = 0, just = "left", width = gtable_width(gt)),
+ left = viewport(x = 1, just = "right", width = gtable_width(gt))
)
absoluteGrob(
- gList(line, gtt),
+ gList(line, gt),
width = gtable_width(gt),
- height = gtable_height(gt)
+ height = gtable_height(gt),
+ vp = justvp
)
}

0 comments on commit b805680

Please sign in to comment.