Combine Multiple ggplot2 Legend in R
In this article, we will see how to combine multiple ggplot2 Legends in the R programming language.
First, load the ggplot2 package by using the library() function. If you have not installed it yet, you can simply install it by writing the below command in R Console.
To create an R plot, we use ggplot() function and for make it scatter plot we add geom_point() function to ggplot() function. Let us first create a plot with multiple legends in the same plot without combining so that the difference is apparent.
As you can see in the above plot the two legends Group1 represents color and Group2 represents shape of Points in scatter plot are differently outlined. To Combine them into one legend, We should choose only one out of both Legends. Here we have chosen Group2, So we assign Group2 to color and shape parameters of aes() function. You can also choose Group1.