Combine Multiple ggplot2 Legend in R Last Updated : 03 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to combine multiple ggplot2 Legends in the R programming language. Installation 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. install.packages("ggplot2") 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. Example: R # Load Package library("ggplot2") # Create a DataFrame data <- data.frame(Xdata = rnorm(6), Ydata = rnorm(6), Group1 = c("ld-01", "ld-02", "ld-03", "ld-04", "ld-05", "ld-06"), Group2 = c("ld-01", "ld-02", "ld-03", "ld-04", "ld-05", "ld-06")) # Create a Scatter Plot With Multiple Legends ggplot(data, aes(Xdata, Ydata, color = Group1, shape = Group2)) + geom_point(size = 7) Output: Scatterplot with multiple legends 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. Example: R # Load Package library("ggplot2") # Create a DataFrame data <- data.frame(Xdata = rnorm(6), Ydata = rnorm(6), Group1 = c("ld-01", "ld-02", "ld-03", "ld-04", "ld-05", "ld-06"), Group2 = c("ld-01", "ld-02", "ld-03", "ld-04", "ld-05", "ld-06")) # Create a Scatter Plot with Combined # multiple legends ggplot(data, aes(Xdata, Ydata, color = Group2, shape = Group2)) + geom_point(size = 7) Output: Scatterplot with Combined multiple Legends Comment More infoAdvertise with us Next Article Add Common Legend to Combined ggplot2 Plots in R E erkrutikpatel Follow Improve Article Tags : R Language R-ggplot Similar Reads How to Combine Multiple ggplot2 Plots in R? In this article, we will discuss how to combine multiple ggplot2 plots in the R programming language. Combining multiple ggplot2 plots using '+' sign to the final plot In this method to combine multiple plots, here the user can add different types of plots or plots with different data to a single p 2 min read Add Common Legend to Combined ggplot2 Plots in R In this article, we will discuss how to create a combined plot with a shared legend in R Language using the ggplot2 package. To join multiple ggplot2 plots, we use the grid.arrange() function of the gridExtra package in the R Language. The grid.arrange() function converts the frame into a grid of th 3 min read Divide Legend of ggplot2 Plot in R In this article, we will discuss how to divide the legend of ggplot2 plot in the R programming language. To divide the legend of the ggplot2 plot, the user needs to install and import the gridExtra and cowplot packages in the R console. gridExrta package: Provides a number of user-level functions to 2 min read Create Legend in ggplot2 Plot in R In this article, we will discuss how to create a legend in ggplot using R programming language. To draw a legend within ggplot the parameter col is used, it basically adds colors to the plot and these colors are used to differentiate between different plots. To depict what each color represents a le 2 min read Add legend for multiple lines in R using ggplot2 In this article, we are going to see how to add legends for multiple line plots in R Programming Language using ggplot2. First, you need to install the ggplot2 package if it is not previously installed in R Studio. The functions used to create the line plots are : geom_line( ) : To plot the line and 3 min read How to change legend title in ggplot2 in R? In this article, we will see how to change the legend title using ggplot2 in R Programming. We will use ScatterPlot. For the Data of Scatter Plot, we will pick some 20 random values for the X and Y axis both using rnorm() function which can generate random normal values, and here we have one more p 3 min read Like