简体   繁体   中英

Alter default settings for cowplot theme

I like the default theme for cowplot , but I want to make some alterations. For example, I'd like to be able to adjust the default for legend.key . A MWE,

library(ggplot2); library(cowplot)

plt = ggplot(mtcars, aes(x = mpg, y = wt, color = factor(cyl))) + geom_point() + theme(legend.key = element_rect(color = 'black'))

plt

However, this doesn't work.
在此处输入图片说明

Is there any way of adjusting the cowplot theme without having to redefine the whole dang thing manually?

The cowplot theme sets the default linetype of rects to 0, which means 'transparent':

rect = element_rect(fill = "transparent", colour = NA, color = NA, size = 0, linetype = 0)

Overriding that default give you what you want:

library(ggplot2)
library(cowplot)

ggplot(mtcars, aes(x = mpg, y = wt, color = factor(cyl))) + 
    geom_point() + 
    theme(legend.key = element_rect(color = 'black', linetype = 1))

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