改变厚度中线geom_boxplot()

时间:2022-03-02 13:06:18

I want to do some modifications of a geom_boxplot(). Because my boxplots are really "small" sometimes (see yellow and green clade in the graphic here) i want to highlight the median even more. so is it possible to adjust the thickness of the median line?

我想对geom_boxplot()进行一些修改。因为我的箱形图有时候很“小”(在图中看到黄色和绿色的分支)我想更加突出中位数。那么可以调整中线的厚度吗?

1 个解决方案

#1


23  

This solution is not obvious from the documentation, but luckily does not require us to edit the source code of ggplot2. After digging through the source of ggplot2 I found that the thickness of the median line is controlled by the fatten parameter. By default fatten has a value of two:

这个解决方案在文档中并不明显,但幸运的是我们不需要编辑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) 

改变厚度中线geom_boxplot()

But if we increase the value to for example 4, the median line becomes thicker.

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

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

改变厚度中线geom_boxplot()

#1


23  

This solution is not obvious from the documentation, but luckily does not require us to edit the source code of ggplot2. After digging through the source of ggplot2 I found that the thickness of the median line is controlled by the fatten parameter. By default fatten has a value of two:

这个解决方案在文档中并不明显,但幸运的是我们不需要编辑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) 

改变厚度中线geom_boxplot()

But if we increase the value to for example 4, the median line becomes thicker.

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

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

改变厚度中线geom_boxplot()