Adding text to a ggplot2 plot at a custom location

When displaying the results of your analysis, even if at exploratory stages, it is crucial to have the ability to customize your data visualization.

One thing I always find particularly useful is using the text annotations on your plot to highlight the findings in the most effective way.

In ggplot2, you can do this using the geom_text() function, moving your string around the plot to adjust the position argument. So, you will have to try and try again until you find the correct position for your handful of words. But, what if you could just select a location for your text by just clicking on it with your cursor?

That is exactly what this recipe is for; you will be able to add a custom text on your ...

Get RStudio for R Statistical Computing Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.