View source: R/geom_contour_tanaka.R
geom_contour_tanaka | R Documentation |
Illuminated contours (aka Tanaka contours) use varying brightness and width to create an illusion of relief. This can help distinguishing between concave and convex areas (local minimums and maximums), specially in black and white plots or to make photocopy safe plots with divergent colour palettes, or to render a more aesthetically pleasing representation of topography.
geom_contour_tanaka(
mapping = NULL,
data = NULL,
stat = "Contour2",
position = "identity",
...,
breaks = NULL,
bins = NULL,
binwidth = NULL,
sun.angle = 60,
light = "white",
dark = "gray20",
range = c(0.01, 0.5),
smooth = 0,
proj = NULL,
proj.latlon = TRUE,
clip = NULL,
kriging = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
breaks |
One of:
|
bins |
Number of evenly spaced breaks. |
binwidth |
Distance between breaks. |
sun.angle |
angle of the sun in degrees counterclockwise from 12 o' clock |
light , dark |
valid colour representing the light and dark shading |
range |
numeric vector of length 2 with the minimum and maximum size of lines |
smooth |
numeric indicating the degree of smoothing of illumination and size. Larger |
proj |
The projection to which to project the contours to. It can be either a projection string or a function to apply to the whole contour dataset. |
proj.latlon |
Logical indicating if the projection step should project from a cartographic projection to a lon/lat grid or the other way around. |
clip |
A simple features object to be used as a clip. Contours are only drawn in the interior of this polygon. |
kriging |
Whether to perform ordinary kriging before contouring.
Use this if you want to use contours with irregularly spaced data.
If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_contour_tanaka
understands the following aesthetics (required aesthetics are in bold)
x
y
z
linetype
library(ggplot2)
library(data.table)
# A fresh look at the boring old volcano dataset
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
geom_contour_fill(aes(z = value)) +
geom_contour_tanaka(aes(z = value)) +
theme_void()
# If the transition between segments feels too abrupt,
# smooth it a bit with smooth
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
geom_contour_fill(aes(z = value)) +
geom_contour_tanaka(aes(z = value), smooth = 1) +
theme_void()
data(geopotential)
geo <- geopotential[date == unique(date)[4]]
geo[, gh.z := Anomaly(gh), by = lat]
# In a monochrome contour map, it's impossible to know which areas are
# local maximums or minimums.
ggplot(geo, aes(lon, lat)) +
geom_contour2(aes(z = gh.z), color = "black", xwrap = c(0, 360))
# With tanaka contours, they are obvious.
ggplot(geo, aes(lon, lat)) +
geom_contour_tanaka(aes(z = gh.z), dark = "black",
xwrap = c(0, 360)) +
scale_fill_divergent()
# A good divergent color palette has the same luminosity for positive
# and negative values.But that means that printed in grayscale (Desaturated),
# they are indistinguishable.
(g <- ggplot(geo, aes(lon, lat)) +
geom_contour_fill(aes(z = gh.z), xwrap = c(0, 360)) +
scale_fill_gradientn(colours = c("#767676", "white", "#484848"),
values = c(0, 0.415, 1)))
# Tanaka contours can solve this issue.
g + geom_contour_tanaka(aes(z = gh.z))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.