Edit legend generated in ggpairs

I created a ggpairs plot of mtcars database, using variable "vs" as a factor to categorize the plot by color. The legend comes back with the factor() call I'm using, and I want to change the legend title to "Engine Type". ggpairs doesn't seem to like the labs() function. Can anyone assist, please?

suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(GGally))
mtcars %>% ggpairs(., legend = 1, columns = c(1,3,4,6), 
                   aes(color = factor(vs, levels = 0:1, labels = c("V-Block", "Straight")))) + 
  theme(legend.position = "bottom") + 
  labs(color = "Engine Type")

Created on 2020-04-06 by the reprex package (v0.3.0)

That is a fill legend, not a color legend. So using labs(fill = "Engine Type") works.

Yes, that is confusing, but tweaking the output of very non-standard ggplot functions like ggpairs often is.

3 Likes

That worked perfectly - thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.