gpt4 book ai didi

r - 如何在格子 bwplot 中手动设置多个箱线图的比例?

转载 作者:行者123 更新时间:2023-12-02 08:30:58 25 4
gpt4 key购买 nike

我得到了聚类的结果,并决定使用格子为每个聚类制作一个箱线图。接下来,我需要建立一个所有聚类箱线图都能接受的比例。

First attempt

找到了一个解决方案,允许排除异常值并设置自由关系。

library(lattice)
trellis.device(new=FALSE, col=FALSE)

bwplot(value ~ variable | Cluster, data = test,
layout = c(2,2),
prepanel = function(x, y) {
bp <- boxplot(split(y, x), plot = FALSE)
ylim <- range(bp$stats)
list(ylim = ylim) },
scales = list(y = list(relation = "free")),
do.out = F)

所以,我得到了非常好的图,但如果我为每个图手动设置 ylim 会更好。例如,我的数据中只有整数值,左上角聚类图中的值 0.5 没有意义。 Second

那么,有什么方法可以在bwplot参数中设置多个ylim吗?

最佳答案

来自 ?bwplot 下的文档:

xlim could also be a list, with as many components as the number of panels (recycled if necessary), with each component as described above. This is meaningful only when scales$x$relation is "free", in which case these are treated as if they were the corresponding limit components returned by prepanel calculations.

ylim 参数具有 y 轴的相应功能。

因此,在 scales 参数中设置 relation = "free",然后将列表传递给 ylim 参数为每个面板单独设置 y 轴限制:

bwplot(len ~ factor(dose) | supp, data = ToothGrowth,
scales = list(relation = "free"),
ylim = list(c(5, 31), c(0, 36)))

enter image description here

关于r - 如何在格子 bwplot 中手动设置多个箱线图的比例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863488/

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