custom axis width with theme after loading cowplot

最后都变了- 提交于 2019-12-24 19:31:55

问题


I am trying to make the X and Y axis lines thicker using theme(axis.line=element_line(size=2)) but cowplot is overriding it. Is there a way to specify XY axis lines size while using cowplot?

I tried adding theme(axis.line=element_line(size=2)) to my plot. Cowplot typically respects specifications I pass to theme, but not this one.

library(ggplot2)

ggplot(mpg, aes(x=trans, y=cty)) +
  geom_boxplot() +
  theme( axis.line = element_line(size = 2))
# correct plot

########

library(ggplot2)
library(cowplot)

ggplot(mpg, aes(x=trans, y=cty)) +
  geom_boxplot() +
  theme( axis.line = element_line(size = 2))
# ignores size. 

I would like to manually specify the size (thickness) of axis lines while using cowplot if possible.


回答1:


Specifying the axis (i.e. X or Y) in the call to theme() fixes this issue as @ClausWilke pointed out in the comments.

library(ggplot2)
library(cowplot)

ggplot(mpg, aes(x=trans, y=cty)) +
  geom_boxplot() +
  theme(axis.line.x = element_line(size = 2),
        axis.line.y = element_line(size = 2))


来源:https://stackoverflow.com/questions/54244928/custom-axis-width-with-theme-after-loading-cowplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!