简体   繁体   English

如何为箱线图创建合适的数据集

[英]How to create a proper dataset for boxplots

I'm having trouble to create a proper boxplot of my dataset.我无法为我的数据集创建正确的箱线图。 All of the solutions on this platform don't work because their dataset all look different with variables against each other.这个平台上的所有解决方案都不起作用,因为它们的数据集看起来都不同,变量彼此相对。

So I want to ask: how do I need to format my dataset if it only contains 3 variables and their measured values in 3 columns.所以我想问:如果我的数据集只包含 3 个变量及其在 3 列中的测量值,我需要如何格式化我的数据集。 In the boxplot examples here, they plot a variable against another one but here this is not the case right?在这里的箱线图示例中,他们针对另一个变量绘制了一个变量,但在这里情况并非如此,对吗?

Using boxplot(data) gives me 3 boxplots.使用 boxplot(data) 给了我 3 个 boxplots。 But I want to show the MEAN and also the population size on each boxplot.但我想在每个箱线图上显示均值人口规模 I don't know how to use the solution as they are all about ggplot2 or boxplot with variables against each other.我不知道如何使用该解决方案,因为它们都是关于 ggplot2 或 boxplot 的,并且变量彼此相对。

I know that this must be simple, but I think I'm plotting the boxplots on a bad method and that's why the solutions on this site don't work?我知道这一定很简单,但我认为我正在用一种错误的方法绘制箱线图,这就是为什么该站点上的解决方案不起作用的原因?

Data:数据:

structure(list(Rest = c(3.479386607, 3.478445796, 2.52227462, 1.726115552, 3.917693859, 2.300840122), Peat = c(16.79515746, 22.76673699, 24.43289941, 15.64168939, 31.60459098, 16.2369787 ), Top.culture = c(8.288, 8.732, 5.199, 6.539, 3.248, 10.156)), .Names = c("Rest", "Peat", "Top.culture"), row.names = c(NA, 6L), class = "data.frame")结构(列表(休息= C(3.479386607,3.478445796,2.52227462,1.726115552,3.917693859,2.300840122),泥煤= C(16.79515746,22.76673699,24.43289941,15.64168939,31.60459098,16.2369787),Top.culture = C(8.288,8.732,5.199, 6.539, 3.248, 10.156)), .Names = c("Rest", "Peat", "Top.culture"), row.names = c(NA, 6L), class = "data.frame")

If text annotation is what is meant by 'show the mean and also the population size' then:如果文本注释是“显示平均值和人口规模”的意思,那么:

boxplot(dat)
text(1:3, 12.5, paste( "Mean= ",round(sapply(dat,mean, na.rm=TRUE), 2), 
                       "\n N= ", 
                        sapply(dat, function(x) length( x[!is.na(x)] ) )
      )              )

在此处输入图片说明

This used your more complex data-object from the other (duplicated) question.这使用了来自另一个(重复)问题的更复杂的数据对象。

dat <- structure(list(Rest = c(3.479386607, 3.478445796, 2.52227462, 1.726115552, 3.917693859, 2.300840122, 2.326307503, 2.344828287, 4.654278623, 3.68669447, 3.343706863, 0.712228306, 2.735897248, 1.936723375, 2.724260325, 2.069633651, 1.741484154, 2.304391217, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Peat = c(16.79515746, 22.76673699, 24.43289941, 15.64168939, 31.60459098, 16.2369787, 32.63285246, 35.91852324, 19.27802839, 21.78974576, 30.39119451, 35.4846573, 42.21807817, 42.00913743, 40.96996704, 19.85075354, 17.247096, 22.81689524, 43.35990368, 37.57273508, 23.76889902, 38.34604591, 20.98376674, 16.44173119, 17.27639888, NA, NA, NA, NA, NA, NA), Top.culture = c(8.288, 8.732, 5.199, 6.539, 3.248, 10.156, 3.436, 5.584, 4.483, 2.087, 3.28, 2.71, 2.196, 4.971, 4.475, 6.361, 5.49, 9.085, 3.52, 5.772, 9.308, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("Rest", "Peat", "Top.culture" ), class = "data.frame", row.names = c(NA, -31L))

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

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