grid_zoom.Rd
This function takes a grob object (e.g. created with package grid) and adds a zoom window.
grid_zoom(inputGrob = pointsGrob(runif(200),runif(200)),
inputViewport = viewport(name='main'),
x = 'topleft', y, just,
ratio = c(.3,.4), zoom_xlim, zoom_ylim,
rect = TRUE, rect_lwd = 1, rect_fill = 'gray92',
draw =TRUE, zoom_fill = 'white',
zoom_frame_gp = gpar(lwd = 1),
zoom_gp = NULL, zoom_xaxis = xaxisGrob(main = FALSE),
zoom_yaxis = NULL)
A grob object, e.g created with package grid.
Viewport related to inputGrob
.
Specifies the x
coordinate of the zoom
window. Alternatively it can be set to 'topleft', 'topright',
'bootmleft' or 'bootmright'
Specifies the y
coordinate of the zoom
window.
Specifies the justification of the zoom window.
Specifies size of the zoom window relative to the main window.
Specifies xlim value of the zoom window.
Specifies ylim value of the zoom window.
Logical, if TRUE a rectangle of the zoom region is draw in the main window.
lwd of the rectangle.
fill of the rectangle.
logical, if TRUE the returned grob object is also drawn.
fill color of the zoom window.
gpar() of the frame of the zoom window.
gpar() of the inputGrob in the zoom viewport.
xaxisGrob() to draw for the zoom window.
yaxisGrob() to draw for the zoom window.
A grob object.
A zoom plot does only make sense if all objects of the inputGrob
are specified in native
units. Additional caution me be require
for certain grobs: e.g. a zoom of a circleGrob() is problematic if the x
and y axis are stretched by a different amount.
grid_trace2
require(grid)
#> Loading required package: grid
## -- Example 1 --
set.seed(133)
grid_zoom(inputGrob = pointsGrob(runif(200), runif(200)),
inputViewport = viewport(name = 'main'),
zoom_xlim = c(.2, .3), zoom_ylim = c(.2, .3))
## -- Example 2 --
## initial plot
grid.newpage()
vp <- viewport(width=.8, height=.8, clip='on')
gt <- gTree(children=gList(polylineGrob(x=c((0:4)/10, rep(.5, 5), (10:6)/10, rep(.5, 5)),
y=c(rep(.5, 5), (10:6/10), rep(.5, 5), (0:4)/10),
id=rep(1:5, 4), default.units='native',
gp=gpar(col=1:5, lwd=3)),
pointsGrob(runif(1000), runif(1000),pch='.', gp=gpar(cex=3)),
rectGrob(gp=gpar(lwd=3))))
pushViewport(vp)
grid.draw(gt)
## plot with zoom window
grid.newpage()
grid_zoom(inputGrob = gt,
inputViewport = vp,
x='topright', zoom_xlim=c(.6,.73), zoom_ylim=c(.3,.43),ratio=.4,
zoom_xaxis = NULL, zoom_gp = gpar(cex=3))