To produce a publication-quality data visualization, we often need to annotate the graph with various texts, symbols, or even shapes. In this recipe, we will learn how we can easily annotate an existing graph.
In this recipe, we will use the disA
and disD
variables from ggplotdata
. Let's call ggplotdata
for this recipe. We also need to call the grid
and gridExtra
libraries for this recipe.
In this recipe, we will execute the following annotation on an existing scatter plot. So, the whole procedure will be as follows:
Create a scatter plot.
Add customized text within the plot.
Highlight a certain region to indicate extreme values.
Draw a line segment with an arrow within the scatter plot to indicate a single extreme observation.
Now, we will implement each of the steps one by one:
library(grid) library(gridExtra) # creating scatter plot and print it annotation_obj <- ggplot(data=ggplotdata,aes(x=disA,y=disD))+geom_point() annotation_obj...