Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide the part of the legend using ggplot2?

Tags:

I am generating a plot using the code below and would like to hide the "mag" (size) legend but still keep the "depth" (color) legend.

ggplot(quakes, aes(long, lat, size=mag, colour=depth)) + geom_point()

like image 412
user338714 Avatar asked Nov 17 '10 17:11

user338714


People also ask

How do you suppress a legend in ggplot2?

By specifying legend. position=”none” you're telling ggplot2 to remove all legends from the plot.

How do I hide the legend in R?

Output: Now to hide the legend, theme() function is used after normally drawing the plot. theme() function is a powerful way to customize the non-data components of your plots: i.e. titles, labels, fonts, background, gridlines, and legends.

How do I remove a fill legend in R?

For example, if we make a boxplot with fill argument, we use “guides(fill=FALSE)” to remove legend.

How do I remove a legend label?

One of the ways to remove legend title is to use scale_fill_discrete() function with name=”” as argument. Here we use scale_fill_discrete() as we have the legend from “fill” argument while making barplots.


1 Answers

Try:

... + scale_size(guide="none") # As of Mar 2012

... + scale_size(legend = FALSE) # Deprecated
like image 63
Brandon Bertelsen Avatar answered Nov 21 '22 15:11

Brandon Bertelsen