You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ggplot2使用theme_classic主题调用geom_boxplot时无法移除x轴刻度和文本

报错原因
  • ggplot2的预设主题函数(包括theme_classic()、theme_bw()等)仅支持接收基础字号、字体、边距这类全局主题参数,不支持直接传入axis.text.x、axis.ticks.x这类单元素修改参数,这是触发「unused arguments」报错的根本原因。
  • 要在预设主题基础上修改局部元素,需要额外叠加theme()函数传入自定义参数。
修正后可运行代码
p2 <- ggplot(data = sal_pH, aes(x = NULL, y = quant)) +
    stat_boxplot(geom = "errorbar", width = 0.3) + 
    geom_boxplot(
        color='#00008B',
        fill='#00008B',
        alpha=0.4,
        outlier.color='blue1',
        outlier.fill='white',
        outlier.size=2
    ) +
    coord_flip() +
    theme_classic() + # 先加载经典主题预设
    theme( # 单独传入自定义主题修改项
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank()
    ) +
    xlab('Salem') +
    ylab('pH') +
    ylim(6.0, 10.0)

补充说明:由于你调用了coord_flip()翻转了坐标轴,如果你实际想要移除的是翻转后位于水平方向的原Y轴刻度,将上述theme()中的axis.text.x、axis.ticks.x替换为axis.text.y、axis.ticks.y即可。

内容的提问来源于stack exchange,提问作者Rich Shepard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 06:27:02