knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "50%" )
This package provides a ggplot2 interface to the isoband library which can generate contour lines (isolines) and contour polygons (isobands) from regularly spaced grids containing elevation data.
Install from github with:
devtools::install_github("clauswilke/ggisoband")
We can draw contour lines and contour bands, including partially transparent contour bands.
library(ggplot2) library(ggisoband) volcano3d <- reshape2::melt(volcano) names(volcano3d) <- c("x", "y", "z") ggplot(volcano3d, aes(x, y, z = z)) + geom_isobands(aes(color = stat(zmin)), fill = NA) + scale_color_viridis_c() + coord_cartesian(expand = FALSE) + theme_bw() ggplot(volcano3d, aes(x, y, z = z)) + geom_isobands(aes(fill = stat(zmin)), color = NA) + scale_fill_viridis_c(guide = "legend") + coord_cartesian(expand = FALSE) + theme_bw() # set polygon_outline = FALSE when drawing filled polygons # with alpha transparency ggplot(volcano3d, aes(x, y, z = z)) + geom_isobands( aes(fill = stat(zmin)), color = NA, alpha = 0.5, polygon_outline = FALSE ) + scale_fill_viridis_c(guide = "legend") + coord_cartesian(expand = FALSE) + theme_bw()
We can also draw contour bands derived from a 2D density estimation.
ggplot(faithful, aes(eruptions, waiting)) + geom_density_bands(aes(fill = stat(density)), color = "gray40", alpha = 0.7, size = 0.2) + geom_point(shape = 21, fill = "white") + scale_fill_viridis_c(guide = "legend")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.