# NOT RUN {
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")
# }
Run the code above in your browser using DataLab