[R] How to change legend key size in ggplot2

[This article was first published on R on Zhenguo Zhang's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Zhenguo Zhang’s Blog https://fortune9.netlify.app/2026/04/27/r-how-to-change-legend-key-size-in-ggplot2/ –

In ggplot2, the legend keys (the symbols next to the labels) usually inherit their size and appearance from the layers in the plot. For example, if you have a scatter plot with very small points, the legend keys will also be very small, making them hard to see.

To fix this without changing the size of the points in the actual plot, you can use the override.aes argument within guide_legend().

The Problem: Tiny Legend Keys

When plotting many data points, we often decrease the size to avoid overplotting. However, this makes the legend keys tiny:

library(ggplot2)

p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point(size = 0.5) + 
  theme_minimal() +
  labs(title = "Tiny Legend Keys")

p

The Solution: Using override.aes

By using guides(), we can “override” the aesthetics of the legend. This allows us to keep the small points in the plot while making the legend keys large and clear.

If your legend is for the color aesthetic:

p_fixed <- p + 
  guides(color = guide_legend(override.aes = list(size = 5))) +
  labs(title = "Fixed Legend Keys (Size 5)")

p_fixed

If you were using fill (e.g., in a bar plot or boxplot), you would simply change color to fill:

guides(fill = guide_legend(override.aes = list(size = 5)))

Adjusting Legend Text and Title Size

Note that override.aes only affects the symbols inside the legend. To change the size of the labels or the legend title, you should use the theme() function:

p_fixed + 
  theme(
    legend.text = element_text(size = 12),   # Legend labels
    legend.title = element_text(size = 14, face = "bold") # Legend title
  )

Summary

  • Use guides(color = guide_legend(override.aes = list(size = ...))) to change the symbol size.
  • Use theme(legend.text = element_text(size = ...)) to change the text size.
- https://fortune9.netlify.app/2026/04/27/r-how-to-change-legend-key-size-in-ggplot2/ -
To leave a comment for the author, please follow the link and comment on their blog: R on Zhenguo Zhang's Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)