You would think to annotate a graph by stringing on more geom calls, like so:
p <- ggplot(ve, aes(x=V1) + stat_ecdf() + geom_vline(xintercept=10)
However, this applies geom_vline for all data in the frame. Instead, get the object from gglot and use annotate()
p <- ggplot(ve, aes(x=V1) + stat_ecdf() p + geom_vline(xintercept=10)
You can also use geom_hline for horizontal lines and geom_abline to specify slope and intercept. And since this is R, you can compute results from your data and use that to place lines or text objects.
The intention is to use annotate(), but ggplot2 originally didn’t have annotate, and geom_vline etc were modifed to handle annotations properly.
annotate(“text”) adds text annotations.
annotate(“segment”) adds line segments.
annotate(“rect”) adds shaded rectangles.
coord_cartesian(xlim=c(..), ylim=c(..)) zooms the viewport in or out to show the specified range. This is generally what you want instead of scale_y_continuous; in the latter, data outside the range is removed from consideration, which can affect presentation.