# NOT RUN {
set.seed(506)
x <- rnorm(10000)
y <- rnorm(10000)
# bin the points
bin <- hexbin(x,y)
# Typical approach uses plot( <hexbin> ) which controls the plot shape :
plot(bin, main = "Bivariate rnorm(10000)")
## but we can have more manual control:
# A mixture distribution
x <- c(rnorm(5000),rnorm(5000,4,1.5))
y <- c(rnorm(5000),rnorm(5000,2,3))
hb2 <- hexbin(x,y)
# Show color control and overplotting of hexagons
## 1) setup coordinate system:
P <- plot(hb2, type="n", main = "Bivariate mixture (10000)")# asp=1
## 2) add hexagons (in the proper viewport):
pushHexport(P$plot.vp)
grid.hexagons(hb2, style= "lattice", border = gray(.1), pen = gray(.6),
minarea = .1, maxarea = 1.5)
library("grid")
popViewport()
## How to treat 'singletons' specially:
P <- plot(hb2, type="n", main = "Bivariate mixture (10000)")# asp=1
pushHexport(P$plot.vp)
grid.hexagons(hb2, style= "nested.centroids", mincnt = 2)# not the single ones
grid.hexagons(hb2, style= "centroids", maxcnt = 1, maxarea=0.04)# single points
popViewport()
# }
# NOT RUN {
<!-- %% FIXME --- this would mix grid- and traditional-graphics -->
# }
# NOT RUN {
<!-- %% ----- would need grid-graphics for 'gpclib' -- aaargs... -->
# }
# NOT RUN {
<!-- % # And if we had all the information... -->
# }
# NOT RUN {
<!-- % if(require(gpclib)){ -->
# }
# NOT RUN {
<!-- % h1 <- chull(x[1:5000], y[1:5000]) -->
# }
# NOT RUN {
<!-- % h2 <- chull(x[5001:10000], y[5001:10000]) -->
# }
# NOT RUN {
<!-- % h2 <- h2+5000 -->
# }
# NOT RUN {
<!-- % h1 <- as(cbind(x[1:5000],y [1:5000])[h1, ], "gpc.poly") -->
# }
# NOT RUN {
<!-- % h2 <- as(cbind(x,y)[h2, ], "gpc.poly") -->
# }
# NOT RUN {
<!-- % plot(hb2, type="n", main = "Bivariate mixture (10000)")# asp=1 -->
# }
# NOT RUN {
<!-- % -->
# }
# NOT RUN {
<!-- % plot(h1,poly.args = list(col ="#CCEBC5"),add = TRUE) -->
# }
# NOT RUN {
<!-- % plot(h2,poly.args = list(col ="#FBB4AE"),add = TRUE) -->
# }
# NOT RUN {
<!-- % plot(intersect(h1, h2), poly.args = list(col = 2), add = TRUE) -->
# }
# NOT RUN {
<!-- % grid.hexagons(hb2, style= "centroids", border = gray(.1), pen = gray(.6), -->
# }
# NOT RUN {
<!-- % minarea = .1, maxarea = 1.5) -->
# }
# NOT RUN {
<!-- % } -->
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab