Change Legend Title in ggplot2 in R (Example) | Modify Text of Plot Legends | scale_color_discrete
Автор: Statistics Globe
Загружено: 2022-02-07
Просмотров: 4070
How to change the text of a ggplot2 legend in the R programming language. More details: https://statisticsglobe.com/change-le...
R code of this video:
set.seed(2468) # Set seed for reproducibility
data <- data.frame(x = c(runif(200, 0, 2), runif(100, 1, 3)), # Create x variable
y = c(runif(200, 1, 3), runif(100, 2, 4)), # Create y variable
group = c(rep("g1", 200), rep("g2", 100))) # Create group variable
install.packages("ggplot2") # Install ggplot2 package
library("ggplot2") # Load ggplot2 package
my_ggplot <- ggplot(data, aes(x, y, group = group)) + # ggplot2 with 2 legends
geom_point(aes(x, y, color = group))
my_ggplot # Print plot with default legend
my_ggplot + scale_color_discrete(name = "My Legend Title No. 1") # Manual legend title
my_ggplot + labs(color = "My Legend Title No. 2") # Manual legend title
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – Group for Discussions & Questions: / statisticsglobe
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – Group for Discussions & Questions: / 12555223
Twitter: / joachimschork
Music by bensound.com
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: