gpt4 book ai didi

r - 在不影响箱线图所依据的数据的情况下限制ggplot中箱线图中y轴的范围

转载 作者:行者123 更新时间:2023-12-02 17:20:40 27 4
gpt4 key购买 nike

<分区>

我正在使用 ggplot 创建箱线图。代码如下:

ggplot(my_data, aes(x = as.factor(viotiko), y = pd_1year, fill = as.factor(viotiko))) + geom_boxplot() +
labs(title="Does the PD differ significantly by 'Viotiko' group?",x="Viotiko Group", y = "PD (pd_1year)")

这将输出以下图表:

Boxplot without limits in the y-axis

接下来,我想关注 y 值的范围 --[0, 0.05] -- 我再次运行更改参数的代码。我并不是要排除数据并改变均值和分布,而只是要关注特定范围的 y 值。代码又是这样的:

ggplot(my_data, aes(x = as.factor(viotiko), y = pd_1year, fill = as.factor(viotiko))) + geom_boxplot() +
labs(title="Does the PD differ significantly by 'Viotiko' group?",x="Viotiko Group", y = "PD (pd_1year)") +
scale_y_continuous(breaks =seq(0, .05, .01), limit = c(0, 0.05))

这返回了警告“删除了 173664 行包含非有限值 (stat_boxplot)”。并输出如下图:

Boxplot after setting a limit to the y axis

显然,ggplot 以某种方式改变了箱线图所基于的输入数据。然而,我的意图只是关注箱线图的一部分,以便我可以更仔细地检查各组之间的差异。我如何使用 ggplot 执行此操作?

我们将不胜感激您的建议。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com