Description Usage Arguments Value Author(s) See Also Examples
This function bins two continuous variables into a hexagonal grid and represents a third variable (which is usually a factor) via piecharts or nested hexagons within the bins. The main idea is to avoid overplotting and unfortunate effects that emerge from mixing up colors, e.g. with alpha-blending.
1 2 3 4 |
x |
The variable for the horizontal axis. Should be integer or numeric. |
y |
The variable for the vertical axis. Should be integer or numeric. |
z |
The target variable for the colors which is handled as a factor. |
n |
The number of bins into which x is divided. See hexbin. |
shape |
There are two possibilities: |
p.rule |
This controls the rules for the representation of the relative frequencies of the target categories.
For |
decr.by.rank |
Whether or not to sort the categories within each hexagon individually by their frequencies in decreasing order.
Defaults to |
freq.trans |
A function which is used to rescale the total counts of the cells. |
alpha.freq |
The frequencies may additionally be reflected in terms of the alpha values of the colors. |
col |
The choice of a color palette. See rmb for further explanations. |
col.opt |
Additional color options to replace the defaults. See rmb for further explanations. |
show.hex |
Whether or not to draw the hexagons. Setting |
random |
If this is not |
xlim |
A vector of length 2 defining the x-limits e.g. computed via innerval . |
ylim |
A vector of length 2 defining the y-limits e.g. computed via innerval . |
label.opt |
Additional labeling options to replace the defaults. Not yet implemented. |
vp |
A viewport to plot in, e.g. for conditional plots. |
invisible(TRUE)
Alexander Pilhoefer
stat_binhex, hexbin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | data(olives)
x <- olives$oleic
y <- olives$linoleic
z <- olives$Region
# the default
hexpie(x,y,z)
## Not run:
# zooming in (transformation of the total number of obs in each bin)
hexpie(x,y,z, freq.trans=sqrt)
# circular shapes
hexpie(x,y,z, freq.trans=sqrt, shape="pie")
# classical piecharts
hexpie(x,y,z, freq.trans=sqrt, shape="pie", p.rule ="angles")
# the total numbers of obs are reflected via alpha-blending,
# the grid is not shown and RGB colors are used
hexpie(x,y,z, freq.trans=sqrt, shape="hex", p.rule ="radial",
alpha.freq=TRUE, col ="rgb",show.hex=F)
hexpie(x,y,z, freq.trans=NULL, shape="hex", p.rule ="radial",
alpha.freq=TRUE, col ="rgb",show.hex=T)
require(ggplot2)
data(diamonds)
x2 <- diamonds$carat
y2 <- diamonds$price
z2 <- diamonds$color
# a standard plot with colors via ggplot2
qplot(x2,y2,colour=z2)
# the hexpie version
hexpie(x2,y2,z2,n=36)
# due to the few bins with the majority of observations
# it is sensible to zoom in
hexpie(x2,y2,z2,n=36,freq.trans=function(s) log(1+s))
# the same, but this time the central color is the most frequent one
hexpie(x2,y2,z2,n=36,freq.trans=function(s) log(1+s), decr.by.rank = TRUE)
# this way the difference is more obvious
# (although the color palette is better suited for ordinal target variables)
mat.layout <- grid.layout(nrow = 1 , ncol = 2 , widths = c(1/2,1/2), heights=1)
grid.newpage()
vp.mat <- viewport(layout = mat.layout)
pushViewport(vp.mat)
vp1 <- viewport(layout.pos.row = 1, layout.pos.col = 1)
pushViewport(vp1)
hexpie(x2,y2,z2,n=18,freq.trans=NULL,
decr.by.rank=NULL,col="div", vp = vp1)
vp2 <- viewport(layout.pos.row = 1, layout.pos.col = 2)
pushViewport(vp2)
hexpie(x2,y2,z2,n=18,freq.trans=NULL,
decr.by.rank=T,col="div", vp = vp1)
popViewport()
# random samples from the data (within bins) with many bins
# (takes some time)
require(scales)
grid.newpage()
hexpie(x2,y2,z2, freq.trans=function(s) log(1+s),random=1,
n=240, show.hex=FALSE, col.opt=list(bg=alpha(1,0.7)),shape="c",col="rgb")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.