View source: R/geom_textdensity2d.R
geom_textdensity2d | R Documentation |
Contour lines representing 2D density are available already in
ggplot2, but the native geom_density_2d
does not allow the lines to be labelled with the level of each contour.
geom_textdensity2d
adds this ability.
geom_textdensity2d( mapping = NULL, data = NULL, stat = "density_2d", position = "identity", ..., contour_var = "density", n = 100, h = NULL, adjust = c(1, 1), lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_labeldensity2d( mapping = NULL, data = NULL, stat = "density_2d", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ..., contour_var = "density", n = 100, h = NULL, adjust = c(1, 1), lineend = "butt", linejoin = "round", linemitre = 10, label.padding = unit(0.25, "lines"), label.r = unit(0.15, "lines"), arrow = NULL )
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, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to
|
contour_var |
Character string identifying the variable to contour
by. Can be one of |
n |
Number of grid points in each direction. |
h |
Bandwidth (vector of length two). If |
adjust |
A multiplicative bandwidth adjustment to be used if 'h' is
'NULL'. This makes it possible to adjust the bandwidth while still
using the a bandwidth estimator. For example, |
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
linemitre |
Line mitre limit (number greater than 1). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
label.padding |
Amount of padding around label. Defaults to 0.25 lines. |
label.r |
Radius of rounded corners. Defaults to 0.15 lines. |
arrow |
Arrow specification, as created by |
A Layer
ggproto object that can be added to a plot.
geom_textdensity2d()
understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
angle
colour
family
fontface
group
hjust
linecolour
lineheight
linetype
linewidth
size
spacing
textcolour
vjust
In addition to aforementioned aesthetics, geom_labeldensity2d()
also understands:
boxcolour
boxlinetype
boxlinewidth
fill
The spacing
aesthetic allows fine control of spacing
of text, which is called 'tracking' in typography.
The default is 0 and units are measured in 1/1000 em.
Numbers greater than zero increase the spacing,
whereas negative numbers decrease the spacing.
Learn more about setting these aesthetics
in vignette("ggplot2-specs")
.
Other geom layers that place text on paths.
set.seed(1) df <- data.frame(x = rnorm(100), y = rnorm(100)) ggplot(df, aes(x, y)) + geom_textdensity2d() + theme_classic()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.