Skip to content

Instantly share code, notes, and snippets.

@aravindhebbali
Last active September 25, 2017 09:22
Show Gist options
  • Save aravindhebbali/567094325b5e134b5b4459677206f363 to your computer and use it in GitHub Desktop.
Save aravindhebbali/567094325b5e134b5b4459677206f363 to your computer and use it in GitHub Desktop.
ggplot2: Text Annotations
# install
install.packages('ggplot2')
install.packages('readr')
# library
library(ggplot2)
library(readr)
# 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')
# Size
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', size = 6)
# Font
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', fontface = 'bold')
# Angle
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text', angle = 25)
# Annotate
ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
annotate('text', x = 200, y = 30, label = 'Sample Text',
color = 'red', size = 6, fontface = 'bold', angle = 25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment