在不绘制箱线图的情况下获取 R 箱线图统计数据
Get R Boxplot stats without drawing the boxplot
我想生成箱线图统计数据(晶须、中位数),我用它来获得两个向量之间的相似性,但是 没有 生成箱线图本身。
让我通过我的代码更好地解释一下:
while(...){
doubleplot <- boxplot(real$dist, result$dist, names=c(paste("Loops (",length(real),")", sep=""),paste("Peak pairs (", length(result), ")",sep="")), ylab="Loop width", cex.lab=1.3, cex.axis=1.3, main="Candidate for negative loops", cex.main=1.5)
correl <- cor(doubleplot$stats[,1],doubleplot$stats[,2])
if(correl>max_correl){
max_correl <- correl
best_plot_data <- doubleplot
}
}
很明显,由于我们在 while 循环中生成箱形图统计数据(有时 100 多个图),因此实际绘制图非常耗费资源。我需要没有情节本身的统计数据。某种 boxplot(..., hidden=TRUE)
您可以使用 boxplot.stats()
。它 returns 一个列表,其中一个元素是 $stats
,您可以在那里访问您想要的内容。
例如
set.seed(1234)
x = rnorm(100)
boxplot.stats(x)
# $stats
# [1] -2.3456977 -0.9006166 -0.3846280 0.4828227 2.5489911
# $n
# [1] 100
# $conf
# [1] -0.6032114 -0.1660445
# $out
# numeric(0)
有关更多信息,您可以查看 ?boxplot.stats()
我想生成箱线图统计数据(晶须、中位数),我用它来获得两个向量之间的相似性,但是 没有 生成箱线图本身。
让我通过我的代码更好地解释一下:
while(...){
doubleplot <- boxplot(real$dist, result$dist, names=c(paste("Loops (",length(real),")", sep=""),paste("Peak pairs (", length(result), ")",sep="")), ylab="Loop width", cex.lab=1.3, cex.axis=1.3, main="Candidate for negative loops", cex.main=1.5)
correl <- cor(doubleplot$stats[,1],doubleplot$stats[,2])
if(correl>max_correl){
max_correl <- correl
best_plot_data <- doubleplot
}
}
很明显,由于我们在 while 循环中生成箱形图统计数据(有时 100 多个图),因此实际绘制图非常耗费资源。我需要没有情节本身的统计数据。某种 boxplot(..., hidden=TRUE)
您可以使用 boxplot.stats()
。它 returns 一个列表,其中一个元素是 $stats
,您可以在那里访问您想要的内容。
例如
set.seed(1234)
x = rnorm(100)
boxplot.stats(x)
# $stats
# [1] -2.3456977 -0.9006166 -0.3846280 0.4828227 2.5489911
# $n
# [1] 100
# $conf
# [1] -0.6032114 -0.1660445
# $out
# numeric(0)
有关更多信息,您可以查看 ?boxplot.stats()