Last active
September 25, 2017 09:22
-
-
Save aravindhebbali/567094325b5e134b5b4459677206f363 to your computer and use it in GitHub Desktop.
ggplot2: Text Annotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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