library(ggplot2)
Use annotate()
to add custom text to a plot. It takes the following arguments:
geom
: specify textx
: x axis locationy
: y axis locationlabel
: custom textcolor
: color of textsize
: size of textfontface
: fontface of textangle
: angle of textggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text')
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', color = 'red')
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', size = 6)
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', fontface = 'bold')
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', angle = 25)
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text',
color = 'red', size = 6, fontface = 'bold', angle = 25)