O'Reilly logo

RStudio for R Statistical Computing Cookbook by Andrea Cirillo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required