更改cowplot主题

时间:2017-05-31 12:46:18

标签: r ggplot2 cowplot

我喜欢cowplot的默认主题,但我想做一些改动。例如,我希望能够调整legend.key的默认值。一个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

但是,这不起作用 enter image description here

有没有办法调整cowplot主题而无需手动重新定义整个事物?

1 个答案:

答案 0 :(得分: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))