简体   繁体   中英

custom axis width with theme after loading cowplot

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.

Specifying the axis (ie 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))

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