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 plot and place it at the defined location with a simple click on the plot itself.
Getting ready
We first need to install and load the ggplot2
and ggmap
packages:
install.packages(c("ggplot2","ggmap")) library(ggplot2) library(ggmap)
How to do it...
Build...