【问题标题】:Unable to get sufficient scaling in a boxplot无法在箱线图中获得足够的缩放比例
【发布时间】:2013-11-26 19:36:33
【问题描述】:

我似乎对缩放有问题,我在这里没有找到任何答案。

我创建了一个箱线图,参数“HR”= 心率和“相位”= 离心机相位。有阶段 0-9。

这是我到目前为止所得到的。

boxplot(HR[Gender=="f"]~Phase[Gender=="f"],main="Heart Rate of Females",font.main=2, xlab="Phase", ylab="Heart Rate (beats/min)", axes=FALSE)
axis(side=1,at=c(0, 1,2,3,4,5,6,7,8,9),labels=c(0,1,2,3,4,5,6,7,8,9), xlim=range(0:10), font.lab=4)
axis(side=2,at=c(0, 60,70,80,90,100,110,120,130),labels=c(0, 60,70,80,90,100,110,120,130),las=1, font.lab=4)

一切似乎都很好。但是,我似乎无法解决将相位 0 绘制在 x 轴上相应的 0 值上的问题。
相反,我在 x 轴的位置 1 上看到相位 0,在 x 轴的位置 2 上看到相位 1,依此类推,直到相位 9 不再位于 x 轴上。

【问题讨论】:

    标签: r boxplot axes


    【解决方案1】:

    我使用您在另一个问题中提供的数据来重现您的箱线图代码。

    df <- data.frame(
      Phase = factor(c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9)),
      HR = c(67, 70, 70, 73, 82, 83, 104, 106, 73, 86, 74, 65, 86, 82, 94, 108, 73, 81, 67, 68),
      Gender = factor(c("female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male")),
      )
    

    然后,我使用 R 中的子集函数创建了第二个只有“女性”观察结果的 data.frame。

    df2 = subset(df,df$Gender=="female")
    

    最后,我使用了 R graphics 包中的 boxplot 函数(如您所做的那样),并且所有阶段都正确显示在 x 轴上。

    boxplot(HR~Phase, data=df2,
        main="Heart Rate of Females",
        xlab="Phase",
        ylab="Heart Rate (beats/min)",
        ylim=c(60,130),
        par(font.lab=4,font.main=2))
    

    箱线图中只有水平线,因为每个阶段只有一个观察值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      相关资源
      最近更新 更多