R 如何修改箱线图的此槽口错误?
我已在我的R 如何修改箱线图的此槽口错误?,r,R,我已在我的箱线图中包含与以下代码有关的槽口: > boxplot(dframe1$High.calcium..diet, dframe1$Low.calcium.diet, # The basic boxplot command + varwidth = FALSE, # width of boxes represents sample size + notch = TRUE,
箱线图
中包含与以下代码有关的槽口:
> boxplot(dframe1$High.calcium..diet, dframe1$Low.calcium.diet, # The basic boxplot command
+ varwidth = FALSE, # width of boxes represents sample size
+ notch = TRUE, # add a notch indicating 95% confidence intervals
+ names = c("High Calcium diet", "Low Calcium diet"), # labels the different boxes
+ col=c("violet", "light green"), # colours the different boxes
+ xlab = "Diet", # adds an x-axis label
+ ylab = "parathyroid hormone per 100 ml blood", # adds a y-axis label
+ cex.lab = 1.6, # adjusts the size of the axis labels
+ cex.axis = 1.3, # adjusts the size of the axis numbering
+ las = 1)
Warning message:
In bxp(list(stats = c(12.7, 14.4, 16.2, 18.25, 23.1, 15.1, 40.2, :
some notches went outside hinges ('box'): maybe set notch=FALSE
>
但是,我收到了如上所述的警告,但我不想将notch
设置为FALSE
,因为我想要的是notch。我该如何解决这个问题
这是随附的数据:
High calcium diet Low calcium diet
14.5 52.7
18.2 44.4
15 125
14.3 66.4
25.7 23.3
17.3 88.3
23.1 38.8
16.2 42.9
12.7 15.1
18.3 41.6
13.2 53.2
这意味着置信区间(即缺口大小)大于四分位间距(IQR)。槽口的大小取决于您的数据:
+/-1.58 IQR/sqrt(n)
请参见?boxplot.stats
如果取样量较大(增加n
),槽口的大小可能会减小
您还可以决定绘制无凹口的箱线图,并手动将标记添加到置信限
创建不带槽口的箱线图:
boxplot(dframe1, notch=F, ylim=c(0,125))
检索数据框中两列的置信区间:
ci_high = boxplot.stats(dframe1[,1], do.conf=T)$conf
ci_low = boxplot.stats(dframe1[,2], do.conf=T)$conf
将这些添加到绘图中:
points(x=c(1,1), y=ci_high, col=2, pch=8)
points(x=c(2,2), y=ci_low, col=2, pch=8)
我可能会先看看
框中铰链的范围
@koekenbakker,我会把它作为一个答案。您还可以指出,如果OP不关心丑陋的槽口,只想消除他们可以使用的警告?suppressWarnings
…这里没有什么真正需要修复的,它只是告诉您一些槽口超出了框。但这并没有错,这只是数据产生的结果。