无法在箱线图中获得足够的缩放比例

时间:2013-11-26 19:36:34

标签: r boxplot axes

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

我创建了一个参数“HR”= Heartrate和“Phase”= Centrifuge Phase的箱线图。阶段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轴上。

1 个答案:

答案 0 :(得分:0)

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

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))

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

enter image description here