简体   繁体   中英

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() 

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()
  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM