
Text — geom_label - ggplot2
geom_text() adds only text to the plot. geom_label() draws a rectangle behind the text, making it easier to read.
Aesthetic specifications - ggplot2
In geom_text() and geom_label(), you can set size.unit = "pt" to use points instead of millimeters. In addition, ggplot2 provides a conversion factor as the variable .pt , so if you want to draw 12pt text, you can also set size = 12 / .pt .
Create an annotation layer — annotate - ggplot2
When constructing a layer using a stat_*() function, the ... argument can be used to pass on parameters to the geom part of the layer. An example of this is stat_density(geom = "area", outline.type = "both"). The geom's documentation lists which parameters it can accept.
FAQ: Customising - ggplot2
You can change the size using the size argument in geom_text() for a single plot. If you want to use the same updated size, you can set this with update_geom_defaults(), e.g. update_geom_defaults("text", list(size = 6)). One tricky thing is that this size is in mm while the size of element_text() is in pt.
Package index • ggplot2
A layer combines data, aesthetic mapping, a geom (geometric object), a stat (statistical transformation), and a position adjustment. Typically, you will create layers using a geom_ function, overriding the default position and stat if needed.
Visualise sf objects — CoordSf • ggplot2
geom_sf() is an unusual geom because it will draw different geometric objects depending on what simple features are present in the data: you can get points, lines, or polygons. For text and labels, you can use geom_sf_text() and geom_sf_label() .
Layer position adjustments — layer_positions - ggplot2
Some geoms that pair well with dodging are geom_bar(), geom_boxplot(), geom_linerange(), geom_errorbar() and geom_text(). Jittering position_jitter() adds a some random noise to every point, which can help with overplotting.
Construct aesthetic mappings — aes • ggplot2
Aesthetics supplied # to ggplot() are used as defaults for every layer. ggplot (mpg, aes (displ, hwy)) + geom_point ggplot (mpg) + geom_point (aes (displ, hwy)) # Tidy evaluation -----# aes() automatically quotes all its arguments, so you need to use tidy # evaluation to create wrappers around ggplot2 pipelines.
ggplot2 extensions: ggrepel - tidyverse
# Example from https://github.com/slowkow/ggrepel library(ggplot2) library(ggrepel) ## We can repel the text labels away from each other by loading ggrepel and using geom_text_repel instead: set.seed(42) dat <- mtcars[1:8,] ggplot(dat) + geom_point(aes(wt, mpg), color = 'red') + geom_text_repel(aes(wt, mpg, label = rownames(dat))) + theme ...
Line segments and curves — geom_segment - ggplot2
geom_segment() draws a straight line between points (x, y) and (xend, yend). geom_curve() draws a curved line. See the underlying drawing function grid::curveGrob() for the parameters that control the curve.