Draw Scatterplot with Labels in R (3 Examples) | Add Text to Plot in Base R & ggplot2 geom_text
Автор: Statistics Globe
Загружено: 8 февр. 2021 г.
Просмотров: 6 219 просмотров
How to add text labels to a scatterplot in the R programming language. More details: https://statisticsglobe.com/draw-scat...
R code of this video:
data <- data.frame(x = 1:5, # Create example data
y = 1:5,
label = LETTERS[1:5])
plot(data$x, # Draw plot
data$y,
xlim = c(1, 5.25))
text(data$x, # Add labels
data$y,
labels = data$label,
pos = 4)
install.packages("ggplot2") # Install & load ggplot2 package
library("ggplot2")
ggplot(data, aes(x, y, label = label)) + # ggplot2 plot with labels
geom_point() +
geom_text(aes(label = label), hjust = - 0.5)
ggplot(data, aes(x, y, label = label)) + # ggplot2 with some labels
geom_point() +
geom_text(aes(label = ifelse(y >= 3, as.character(label), "")), hjust = - 0.5)
Follow me on Social Media:
Facebook: / statisticsglobecom
Patreon: / statisticsglobe
Pinterest: https://www.pinterest.de/JoachimSchork
Reddit: / joachimschork
Twitter: / joachimschork

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: