Please add a sub-section showing the proper way to create a function that can be chained with ggplot.
For instance, I have an annotation I want to add to several plots that consists of a line segment lying on the x axis, with a label above it representing events that occur along the time (x) axis.
In my original plot, this is accomplished by adding (with +) calls to geom_segment and annotate.
How can these two steps be properly encapsulated into a function (say, add_event) that can be chained like so:
Please add a sub-section showing the proper way to create a function that can be chained with ggplot.
For instance, I have an annotation I want to add to several plots that consists of a line segment lying on the x axis, with a label above it representing events that occur along the time (x) axis.
In my original plot, this is accomplished by adding (with
+
) calls togeom_segment
andannotate
.How can these two steps be properly encapsulated into a function (say,
add_event
) that can be chained like so: