rggplot2ggthemes

Showing colour legend in a theme containing "legend.title = element_blank()"


I'm using the ggthemes "theme_exel_new" theme for a plot, which hides the title of the colour legend through the code legend.title = element_blank() in the function. I've attempted to get the title back by adding theme_excel_new(legend.title = waiver()), returning an unused argument error, as well as specifying a scale through scale_color_viridis(name = "M") which shows no effect at all.

Is there any way as to get the title back?

Reprex:

library(ggplot)
library(ggthemes)
ggplot(mtcars, aes(mpg, disp, colour = gear)) +
geom_point() +
theme_excel_new() 

Solution

  • You can overwrite the theme again with theme().

    library(ggplot)
    library(ggthemes)
    ggplot(mtcars, aes(mpg, disp, colour = gear)) +
      geom_point() +
      theme_excel_new()  +
      theme(
        legend.title = element_text()
      )