Search code examples
rggplot2cowplot

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.


Solution

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