简体   繁体   English

一幅图中具有值(分位数)的R多箱线图

[英]R multi boxplot in one graph with value (quantile)

How to create multiple boxplot with value shown in R ? 如何用R中显示的值创建多个箱形图?

Now I'm using this code 现在我正在使用此代码

boxplot(Data_frame[  ,2] ~ Data_frame[  ,3], ) 

I tried to use this 我试图用这个

boxplot(Data_frame[  ,2] ~   Data_frame[  ,3],     ) 
text(y=fivenum(Data_frame$x), labels =fivenum(Data_frame$x), x=1.25)

But only first boxplot have value. 但是只有第一个箱线图才有价值。 How to show value in all boxplot in one graph. 如何在一张图中的所有箱形图中显示值。

Thank you so much! 非常感谢!

As far as I understand your question (it is not clear how the fivenum summary should be displayed) here is one solution. 据我了解您的问题(尚不清楚应该如何显示fivenum摘要),这是一种解决方案。 It presents the summary using the top axis. 它使用上轴显示摘要。

x <- data.frame( 
    Time = c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3), 
    Value = c(5,10,15,20,30,50,70,80,100,5,7,9,11,15,17,19,17,19,100,200,300,400,500,700,1000,200))

boxplot(x$Value ~ x$Time) 
fivenums <- aggregate(x$Value, by=list(Time=x$Time), FUN=fivenum)
labels <- apply(fivenums[,-1], 1, function(x) paste(x[-1], collapse = ", "))
axis(3, at=fivenums[,1],labels=labels, las=1, col.axis="red")

在此处输入图片说明

Of course you can additionally play with the font size or rotation for this summary. 当然,您可以为此摘要附加字体大小或旋转角度。 Moreover you can break the line in one place, so the label will have smaller width. 此外,您可以在一行中折行,因此标签的宽度较小。

Edit In order to get what have you posted in the comment below you can add 编辑为了获得您在以下评论中发布的内容,您可以添加

text(x = 3 + 0.5, y = fivenums[3,-1], labels=fivenums[3,-1])

and you will get 你会得到

在此处输入图片说明

however it won't be readable for other boxplots. 但是其他箱形图将无法读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM