![]() Let us use color and size to highlight two variables in gapminder data frame. Sometimes we highlight the data by more than one variable. We can use the function scale_colour_discrete() with the argument being the new legend title we want. We know that we used the continent variable to color the data points. Let us say we want to change the title to “Continents”. Sometimes you might want to change the legend title to something more meaningful. Ggplot2 single legend title default How to change legend title with scale_colour_discrete() Note that the legend title by default is “continent”, which is the variable name in the gapminder dataframe. Ggplot(aes(x=lifeExp,y=gdpPercap, col=continent))+ Let us also highlight the data points by the column variable continent. Let us make a scatter plot between gdpPercap and lifeExp. # country continent year lifeExp pop gdpPercap Let us load the packages we need to make the plot. Then we will see an example of changing titles of two legends using labs() and guides(). First we will change the title of a single legend with scale_colour_discrete(). We will see three examples of changing legend titles in ggplot2. ![]() Sometimes, you might want to change the titles of multiple legend titles. In the simplest case, you might want to change the title of a single legend. However, sometimes you might want to change the legend title. When you make a plot with ggplot2 and color/highlight data points by a variable in the input dataframe, ggplot2 uses the name of the variable present in the dataframe. In this post, we will see multiple examples of how to change the legend title in ggplot2. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |