How To Add Text To a Plot in R

Channel:
Subscribers:
53,100
Published on ● Video Link: https://www.youtube.com/watch?v=fzPSBvk2q6A



Category:
Guide
Duration: 2:54
4,534 views
37


This video shows how to add text at arbitrary x, y positions to plots in base R and ggplot2.

If you find this video useful, like, share and subscribe to support the channel!

► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1


Code used in this R Code Clip:

# Add text to a base R plot

# Create plot
plot(mtcars$mpg, mtcars$hp)

# Add text at a given point
text(x = 22, # text x coordinate
y = 220, # text y coordinate
labels = "text", # text label
col = "purple", # text color
cex = 4) # text size


# Add text in ggplot
library(tidyverse)

ggplot(data = mtcars, aes(x = mpg, y = hp)) +
geom_point() + # Create scatterplot
annotate("text", x=22, y=220, # Add text
label = "text",
col = "purple",
size = 18)


* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones.







Tags:
add text to a plot in r
add text to a lot in ggplot
add text to a plot in ggplot2
ggplot text
ggplot2 text
ggplot plot text
plot text
plot text in r
r plot text
plot a word
plot a word in r
plot a string in r
plot a string in ggplot2
plot a character in r
plot a character in ggplot2
string plotting
text plotting in r
put a word on a plot in r
add labels to a plot in r
annotate plots in r
annotate plots in ggplot2
r plotting basics
r programming