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()
By specifying legend. position=”none” you're telling ggplot2 to remove all legends from the plot.
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.
For example, if we make a boxplot with fill argument, we use “guides(fill=FALSE)” to remove legend.
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.
Try:
... + scale_size(guide="none") # As of Mar 2012
... + scale_size(legend = FALSE) # Deprecated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With