hexContour | R Documentation |
Algorithm is a modification of the meandering triangles as described in https://blog.bruce-hill.com/meandering-triangles to work with hexagons. See isolines for details about the output.
hexContour(hexDensity, levels)
hexDensity |
hexDensity object to be contoured. |
levels |
Numeric vector for which contour lines should be generated |
This function is made to follow the same behaviour as isolines. A dedicated plotting function is in the work. Meanwhile, see example of how to plot the output with ggplot2's geom_path.
A list of x, y, and ID, for the contour line at each levels. ID indicates the different line segments making up the contour.
set.seed(133)
x=rnorm(200)
y=rnorm(200)
d = hexDensity(x=x,y=y,bandwidth=0.4)
cutoff=quantile(d@count,0.9)
lines = hexContour(d,cutoff)
library(ggplot2)
library(hexbin)
#plot against density
ggplot()+
geom_point(
aes(x=hcell2xy(d)$x,
y=hcell2xy(d)$y,
col=d@count)
) +
scale_color_viridis_c()+
geom_path(
aes(
x = lines[[1]]$x, y = lines[[1]]$y, group = lines[[1]]$id
)
)
#plot against data points
ggplot() +
geom_point(
aes(x=x,y=y)) +
geom_path(
aes(
x = lines[[1]]$x, y = lines[[1]]$y, group = lines[[1]]$id
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.