2017-05-31 156 views
0

我喜欢cowplot的默认主题,但我想进行一些更改。例如,我希望能够调整legend.key的默认值。一个MWE,更改cowplot主题的默认设置

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 

但是,这是行不通的。
enter image description here

是否有调整cowplot主题,而无需手动重新定义了整个党的事情的方法吗?

回答

1

cowplot主题设置rects的默认线型为0,这意味着 '透明':

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

重写该默认给你你想要的东西:

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

+0

非常感谢! – user13317