首页 文章

改变厚度中线geom_boxplot()

提问于
浏览
9

我想对geom_boxplot()进行一些修改 . 因为我的箱形图有时候真的是"small"(见图中的黄色和绿色的分支here)我想更加突出中位数 . 那么可以调整中线的厚度吗?

1 回答

  • 23

    这个解决方案在文档中并不明显,但幸运的是我们不需要编辑 ggplot2 的源代码 . 在挖掘了 ggplot2 的来源后,我发现中线的粗细由 fatten 参数控制 . 默认情况下 fatten 的值为2:

    require(reshape)
    require(ggplot2)
    cars_melt = melt(cars)
    
    ggplot(aes(x = variable, y = value), data = cars_melt) + 
      geom_boxplot(fatten = 2)
    

    enter image description here

    但是如果我们将值增加到例如4,则中值线变粗 .

    ggplot(aes(x = variable, y = value), data = cars_melt) + 
      geom_boxplot(fatten = 4)
    

    enter image description here

相关问题