加载Cowplot后,带有主题的自定义轴宽度 [英] custom axis width with theme after loading cowplot

查看:55
本文介绍了加载Cowplot后,带有主题的自定义轴宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 theme(axis.line = element_line(size = 2))使X和Y轴线更粗,但是cowplot覆盖了它.有没有一种方法可以在使用Cowplot时指定XY轴线的大小?

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?

我尝试将 theme(axis.line = element_line(size = 2))添加到我的绘图中.Cowplot通常会遵守我传递给 theme 的规范,但不遵守此规范.

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. 

如果可能的话,我想在使用Cowplot时手动指定轴线的尺寸(厚度).

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

推荐答案

在对 theme()的调用中指定轴(即X或Y)可解决此问题,因为@ClausWilke在注释.

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

这篇关于加载Cowplot后,带有主题的自定义轴宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆