Agenda


  • add custom text
  • modify color
  • modify size
  • modify fontface
  • modify angle

Libraries


library(ggplot2)

Annotate


Use annotate() to add custom text to a plot. It takes the following arguments:

  • geom : specify text
  • x : x axis location
  • y : y axis location
  • label : custom text
  • color : color of text
  • size : size of text
  • fontface : fontface of text
  • angle : angle of text

Add Text


ggplot(mtcars) +
  geom_point(aes(disp, mpg)) +
  annotate('text', x = 200, y = 30, label = 'Sample Text')

Color


ggplot(mtcars) +
  geom_point(aes(disp, mpg)) +
  annotate('text', x = 200, y = 30, label = 'Sample Text', color = 'red')