-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgeom_contour_tanaka.Rd
220 lines (188 loc) · 8.72 KB
/
geom_contour_tanaka.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom_contour_tanaka.R
\docType{data}
\name{geom_contour_tanaka}
\alias{geom_contour_tanaka}
\alias{GeomContourTanaka}
\title{Illuminated contours}
\usage{
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
)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}}. If specified and
\code{inherit.aes = TRUE} (the default), it is combined with the default mapping
at the top level of the plot. You must supply \code{mapping} if there is no plot
mapping.}
\item{data}{The data to be displayed in this layer. There are three
options:
If \code{NULL}, the default, the data is inherited from the plot
data as specified in the call to \code{\link[ggplot2:ggplot]{ggplot()}}.
A \code{data.frame}, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
\code{\link[ggplot2:fortify]{fortify()}} for which variables will be created.
A \code{function} will be called with a single argument,
the plot data. The return value must be a \code{data.frame}, and
will be used as the layer data. A \code{function} can be created
from a \code{formula} (e.g. \code{~ head(.x, 10)}).}
\item{stat}{The statistical transformation to use on the data for this layer.
When using a \verb{geom_*()} function to construct a layer, the \code{stat}
argument can be used the override the default coupling between geoms and
stats. The \code{stat} argument accepts the following:
\itemize{
\item A \code{Stat} ggproto subclass, for example \code{StatCount}.
\item A string naming the stat. To give the stat as a string, strip the
function name of the \code{stat_} prefix. For example, to use \code{stat_count()},
give the stat as \code{"count"}.
\item For more information and other ways to specify the stat, see the
\link[ggplot2:layer_stats]{layer stat} documentation.
}}
\item{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 \code{position} argument accepts the following:
\itemize{
\item The result of calling a position function, such as \code{position_jitter()}.
This method allows for passing extra arguments to the position.
\item A string naming the position adjustment. To give the position as a
string, strip the function name of the \code{position_} prefix. For example,
to use \code{position_jitter()}, give the position as \code{"jitter"}.
\item For more information and other ways to specify the position, see the
\link[ggplot2:layer_positions]{layer position} documentation.
}}
\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}'s \code{params} argument. These
arguments broadly fall into one of 4 categories below. Notably, further
arguments to the \code{position} argument, or aesthetics that are required
can \emph{not} be passed through \code{...}. Unknown arguments that are not part
of the 4 categories below are ignored.
\itemize{
\item Static aesthetics that are not mapped to a scale, but are at a fixed
value and apply to the layer as a whole. For example, \code{colour = "red"}
or \code{linewidth = 3}. The geom's documentation has an \strong{Aesthetics}
section that lists the available options. The 'required' aesthetics
cannot be passed on to the \code{params}. Please note that while passing
unmapped aesthetics as vectors is technically possible, the order and
required length is not guaranteed to be parallel to the input data.
\item When constructing a layer using
a \verb{stat_*()} function, the \code{...} argument can be used to pass on
parameters to the \code{geom} part of the layer. An example of this is
\code{stat_density(geom = "area", outline.type = "both")}. The geom's
documentation lists which parameters it can accept.
\item Inversely, when constructing a layer using a
\verb{geom_*()} function, the \code{...} argument can be used to pass on parameters
to the \code{stat} part of the layer. An example of this is
\code{geom_area(stat = "density", adjust = 0.5)}. The stat's documentation
lists which parameters it can accept.
\item The \code{key_glyph} argument of \code{\link[ggplot2:layer]{layer()}} may also be passed on through
\code{...}. This can be one of the functions described as
\link[ggplot2:draw_key]{key glyphs}, to change the display of the layer in the legend.
}}
\item{breaks}{One of:
\itemize{
\item A numeric vector of breaks
\item A function that takes the range of the data and binwidth as input
and returns breaks as output
}}
\item{bins}{Number of evenly spaced breaks.}
\item{binwidth}{Distance between breaks.}
\item{sun.angle}{angle of the sun in degrees counterclockwise from 12 o' clock}
\item{light, dark}{valid colour representing the light and dark shading}
\item{range}{numeric vector of length 2 with the minimum and maximum size of lines}
\item{smooth}{numeric indicating the degree of smoothing of illumination and size.
Larger}
\item{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.}
\item{proj.latlon}{Logical indicating if the projection step should project
from a cartographic projection to a lon/lat grid or the other way around.}
\item{clip}{A simple features object to be used as a clip. Contours are only
drawn in the interior of this polygon.}
\item{kriging}{Whether to perform ordinary kriging before contouring.
Use this if you want to use contours with irregularly spaced data.
If \code{FALSE}, no kriging is performed. If \code{TRUE}, kriging will be performed with
40 points. If a numeric, kriging will be performed with \code{kriging} points.}
\item{na.rm}{If \code{FALSE}, the default, missing values are removed with
a warning. If \code{TRUE}, missing values are silently removed.}
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.
It can also be a named logical vector to finely select the aesthetics to
display.}
\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.}
}
\description{
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.
}
\section{Aesthetics}{
\code{geom_contour_tanaka} understands the following aesthetics (required aesthetics are in bold)
\itemize{
\item \strong{x}
\item \strong{y}
\item \strong{z}
\item \code{linetype}
}
}
\examples{
\dontshow{data.table::setDTthreads(1)}
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))
}
\keyword{datasets}