Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

optShape

Optimal Shape Parameter for Hexbin Viewport


Description

Takes a viewport or a given height and width and returns the shape parameter that will fill the specified plotting region with the appropriately shaped hexagons. If margins are specified the margins are subtracted from height and width before the shape parameter is specified.

Usage

optShape(vp, height = NULL, width = NULL, mar = NULL)

Arguments

vp

a viewport object, optional see details

height

the height of the plotting region, can be numeric or units

width

The width of the plotting region, can be numeric or units

mar

A four element numeric or units vector describing the margins in the order c(bottom, left, top, right)

Value

a scalar numeric value specifiyng shape.

Warning

If a viewport is given as an argument it should already be pushed on the graphics device or it will have null units and a meaningless shape parameter will be returned.

Author(s)

Nicholas Lewin-Koh

See Also

Examples

x <- rgamma(10000,.9)
m <- as.logical(rbinom(10000,1,.17))
x[m] <- -x[m]
y <- rnorm(x,abs(x))
library("grid")
vp <- plotViewport(xscale= range(x)+c(-.5,.5),
                   yscale= range(y)+c(-.5,.5),
             default.units = "native")
grid.newpage()
pushViewport(vp)
grid.rect()
shape <- optShape(vp)
shape
hb <- hexbin(x,y,xbins=40,shape=shape)
grid.hexagons(hb,colramp=BTY)

hexbin

Hexagonal Binning Routines

v1.28.2
GPL-2
Authors
Dan Carr <dcarr@voxel.galaxy.gmu.edu>, ported by Nicholas Lewin-Koh and Martin Maechler <maechler@stat.math.ethz.ch>, contains copies of lattice functions written by Deepayan Sarkar <deepayan.sarkar@r-project.org>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.