plot.hexbin {hexbin}R Documentation

plotting hexagon cells and legend


Plots the counts in an hexbin object using 5 different styles. Provides a legend indicating the count representations.


## S3 method for class 'hexbin':
plot(x, style = , legend = 1, lcex = 1,
      minarea = 0.04, maxarea = 0.8, mincnt = 1, maxcnt = max(x$cnt),
      trans = NULL, inv = NULL,
      colorcut = seq(0, 1, length = min(17, maxcnt)),
      border = NULL, density = NULL, pen = NULL,
      colramp = function(n){ LinGray(n,beg = 90,end = 15) },
      xlab = "", ylab = "", verbose = getOption("verbose"), ...)


x an object of class hexbin.
style string, one of ("colorscale", "lattice", "centroids", "nested.lattice", "nested.centroids"), see hexagons.
legend width of the legend in inches. If False or 0 the legend is not produced.
lcex characters expansion size for the text in the legend
minarea fraction of cell area for the lowest count
maxarea fraction of the cell area for the largest count
mincnt cells with fewer counts are ignored.
maxcnt cells with more counts are ignored.
trans function specifying a transformation for the counts such as sqrt.
inv the inverse transformation of trans.
colorcut vector of values covering [0, 1] that determine hexagon color class boundaries and hexagon legend size boundaries.
border Polygon() border argument. Draw the border for each hexagon
density Polygon() fill argument. 0 causes the polygon not to be filled.
pen Polygon() col argument. Determines the color with which the polygon will be filled
colramp function accepting an integer n as an argument and returning n colors.
xlab xlabel argument to plot().
ylab ylabel argument to plot().
verbose logical indicating if some diagnostic output should happen.
... additional arguments from and passed to plot methods.


The legend function is preliminary. Later version will include refinements and handle extreme cases (small and large) for cell size and counts.

For style, minarea etc, see the Details section of hexagons's help page.

Graphics parameters

This function determines the plot shape, so hexagons appear as hexagons. The process alters graphics parameters. The parameters are reset to that before the function call when the function exits. The function returns the parameters for plotting the hexagons invisibly. Users can store the parameters and reinvoke them to add to the plot. See the third example below.




Dan Carr, ported by Nicholas Lewin-Koh and Martin Maechler.


see in hexagons.

See Also

hexbin, smooth.hexbin, erode.hexbin, hcell, hcell2xy, hboxplot, hdiffplot, hmatplot.


## 1) simple binning of spherical normal:
x <- rnorm(10000)
y <- rnorm(10000)
bin <- hexbin(x,y)

# basic plot
# nested lattice
plot(bin, style= "nested.lattice")

# controlling the colorscheme
plot(bin, colramp=BTY, colorcut=c(0,.1,.2,.3,.4,.6,1))

## 2) A mixture distribution
x <- c(rnorm(5000),rnorm(5000,4,1.5))
y <- c(rnorm(5000),rnorm(5000,2,3))
bin <- hexbin(x,y)

pens <- cbind(c("#ECE2F0","#A6BDDB","#1C9099"),
plot(bin, style = "nested.lattice", pen=pens)
# now really crazy
plot(bin, style = "nested.lattice", pen=pens,border=2,density=35)

# lower resolution binning and overplotting with counts
oldpar <- par(no.readonly=TRUE)
bin <- hexbin(x,y,xbins=25)
scrPar <- plot.hexbin(bin, style= "lattice",legend=FALSE,
par(scrPar) # reset graphics to the plot on the screen
xy <- hcell2xy(bin)
points(x,y,pch=18,col="red") # to show points rather than counts
par(oldpar) # reset graphics

# Be creative, have fun!

[Package hexbin version 1.0.10 Index]