| geom_contour2 {metR} | R Documentation | 
2d contours of a 3d surface
Description
Similar to ggplot2::geom_contour but it can label contour lines,
accepts accepts a function as the breaks argument and and computes
breaks globally instead of per panel.
Usage
geom_contour2(
  mapping = NULL,
  data = NULL,
  stat = "contour2",
  position = "identity",
  ...,
  lineend = "butt",
  linejoin = "round",
  linemitre = 1,
  breaks = MakeBreaks(),
  bins = NULL,
  binwidth = NULL,
  global.breaks = TRUE,
  na.rm = FALSE,
  na.fill = FALSE,
  skip = 1,
  margin = grid::unit(c(1, 1, 1, 1), "pt"),
  label.placer = label_placer_flattest(),
  show.legend = NA,
  inherit.aes = TRUE
)
stat_contour2(
  mapping = NULL,
  data = NULL,
  geom = "contour2",
  position = "identity",
  ...,
  breaks = MakeBreaks(),
  bins = NULL,
  binwidth = NULL,
  proj = NULL,
  clip = NULL,
  kriging = FALSE,
  global.breaks = TRUE,
  na.rm = FALSE,
  na.fill = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)
Arguments
| 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, either as a  | 
| position | Position adjustment, either as a string naming the adjustment
(e.g.  | 
| ... | Other arguments passed on to  | 
| lineend | Line end style (round, butt, square). | 
| linejoin | Line join style (round, mitre, bevel). | 
| linemitre | Line mitre limit (number greater than 1). | 
| breaks | One of: 
 | 
| bins | Number of evenly spaced breaks. | 
| binwidth | Distance between breaks. | 
| global.breaks | Logical indicating whether  | 
| na.rm | If  | 
| na.fill | How to fill missing values. 
 | 
| skip | number of contours to skip for labelling
(e.g.  | 
| margin | the margin around labels around which contour lines are clipped to avoid overlapping. | 
| label.placer | a label placer function. See  | 
| show.legend | logical. Should this layer be included in the legends?
 | 
| inherit.aes | If  | 
| geom | The geometric object to use to display the data, either as a
 | 
| 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. | 
| 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  | 
Aesthetics
geom_contour2 understands the following aesthetics (required aesthetics are in bold):
Aesthetics related to contour lines:
-  x 
-  y 
-  z 
-  alpha
-  colour
-  group
-  linetype
-  size
-  weight
Aesthetics related to labels:
-  label
-  label_colour
-  label_alpha
-  label_size
-  family
-  fontface
Computed variables
- level
- height of contour 
See Also
Other ggplot2 helpers: 
MakeBreaks(),
WrapCircular(),
geom_arrow(),
geom_contour_fill(),
geom_label_contour(),
geom_relief(),
geom_streamline(),
guide_colourstrip(),
map_labels,
reverselog_trans(),
scale_divergent,
scale_longitude,
stat_na(),
stat_subset()
Other ggplot2 helpers: 
MakeBreaks(),
WrapCircular(),
geom_arrow(),
geom_contour_fill(),
geom_label_contour(),
geom_relief(),
geom_streamline(),
guide_colourstrip(),
map_labels,
reverselog_trans(),
scale_divergent,
scale_longitude,
stat_na(),
stat_subset()
Examples
library(ggplot2)
# Breaks can be a function.
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
    geom_contour2(aes(z = value, color = after_stat(level)),
                  breaks = AnchorBreaks(130, binwidth = 10))
# Add labels by supplying the label aes.
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
    geom_contour2(aes(z = value, label = after_stat(level)))
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
    geom_contour2(aes(z = value, label = after_stat(level)),
                  skip = 0)
# Use label.placer to control where contours are labelled.
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
    geom_contour2(aes(z = value, label = after_stat(level)),
                      label.placer = label_placer_n(n = 2))
# Use the rot_adjuster argument of the placer function to
# control the angle. For example, to fix it to some angle:
ggplot(reshape2::melt(volcano), aes(Var1, Var2)) +
    geom_contour2(aes(z = value, label = after_stat(level)),
                  skip = 0,
                  label.placer = label_placer_flattest(rot_adjuster = 0))