Once your
chart is done, annotating it is a crucial step to make it more
insightful. This post will guide you through the best practices using
R
and ggplot2
.
geom_text()
or
geom_label()
Text is the most common kind of annotation. It allows to give more information on the most important part of the chart.
Using ggplot2
, 2 main functions are available for that
kind of annotation:
geom_text
to add a simple piece of textgeom_label
to add a label: framed textNote that the annotate()
function is a good alternative
that can reduces the code length for simple cases.
annotate()
The annotate()
function allows to add all kind of shape
on a ggplot2
chart. The first argument will control what
kind is used: rect
or segment
for rectangle,
segment or arrow.
geom_hline()
and
geom_vline()
An abline is a segment that goes from one chart extremity to the
other. ggplot2
offers the geom_hline()
and
geom_vline()
functions that are dedicated to it.
pointrange()
Last kind of annotation, add a dot and a segment directly with
pointrange()
.
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Based on The R Graph Gallery by Yan Holtz.