ggplot - 使中位数不可见 geom_boxplot
ggplot - make the median invisible geom_boxplot
出于某些不明确的原因,我必须绘制一个没有明显中值的箱线图。我怎样才能做到这一点(最好使用ggplot
,但如果有必要我会切换到boxplot
)请问?
相关回答:
- 使用
fatten
参数:我尝试将 fatten 参数设置为 0,
以下 this 回答。留下一条细线。
- 使用
geom_segment
:我尝试使用 this method. But superposing a white segment onto the median line is unsatisfactory because the edges of the box are also erased. I think this approach would work using boxplot
though, since, as can be seen here 将白色部分叠加到中位数上,可以在不影响框边缘的情况下更改中位数的颜色。
一种 "hacky" 方法是在您 post 编辑的答案中使用 fatten
参数,但将其设置为 NULL
。请注意,由于您没有 post 任何数据,我使用 mtcars
内置的 R 数据集。这看起来像:
library(ggplot2)
ggplot(data = mtcars) + geom_boxplot(aes(x = as.factor(am), y = hp), fatten = NULL)
出于某些不明确的原因,我必须绘制一个没有明显中值的箱线图。我怎样才能做到这一点(最好使用ggplot
,但如果有必要我会切换到boxplot
)请问?
相关回答:
- 使用
fatten
参数:我尝试将 fatten 参数设置为 0, 以下 this 回答。留下一条细线。 - 使用
geom_segment
:我尝试使用 this method. But superposing a white segment onto the median line is unsatisfactory because the edges of the box are also erased. I think this approach would work usingboxplot
though, since, as can be seen here 将白色部分叠加到中位数上,可以在不影响框边缘的情况下更改中位数的颜色。
一种 "hacky" 方法是在您 post 编辑的答案中使用 fatten
参数,但将其设置为 NULL
。请注意,由于您没有 post 任何数据,我使用 mtcars
内置的 R 数据集。这看起来像:
library(ggplot2)
ggplot(data = mtcars) + geom_boxplot(aes(x = as.factor(am), y = hp), fatten = NULL)