【发布时间】:2014-08-12 22:56:34
【问题描述】:
(:
我对 R 了解不多,但我需要使用它从数据集合中绘制一组箱线图。
我有一组代表一组二维数据的 .csv 文件。它们包含以下列:
i:矩阵的行
j:矩阵的列
VBoot:矩阵的一个属性
我的数据是 128 x 128,但 .csv 只包含非零属性的索引。
我必须为这些文件中的每一个并排绘制一个箱线图。
这是我的方法:
library(ggplot2)
library(reshape)
# Set the directory to read the files
setwd("/Users/me/data/CSV/")
operatorProperty <- function(operator, property, degrees, m, n)
{
p <- list()
for (degree in degrees)
{
file <- paste(c(degree, operator, property, ".csv"), collapse="")
data <- read.csv(file, header=TRUE, sep=" ", dec=".")
# Create an array m * n to fill with the data
b <- vector(mode="double", length=(m*n))
# Rebuild the complete data to properly build the box plot
b[data$i * m + data$j] = sqrt(data$VBoot)
p <- append(p, list(b))
}
p
}
到目前为止,我刚刚创建了一个列表来插入每个 ensamble 的数据。
那么,我虽然应该建立一个data.frame:
min_degree = 0
max_degree = 45
delta = 5
m = 128
n = 128
degrees <- seq(min_degree, max_degree, delta)
property <- "VBoot"
operator <- "Prewitt"
Sobel <- operatorProperty(operator, property, degrees, m, n)
df <- data.frame(degrees, Sobel)
df2<- melt(data=df,id.vars="degrees")
p <- ggplot(df2, aes(x=degrees,y=value,colour=variable)) +
geom_boxplot() +
theme(legend.title=element_blank()) +
xlab(expression(theta)) +
ylab("Bootstrap Variance")
但是,我无法构建 data.frame。我不知道该怎么做。数据示例可以在here找到。
提前谢谢你。
【问题讨论】:
-
你希望最终的情节是什么样子的?您是否只想为每个文件中的非零值制作箱线图?或者你想让所有的零也算在内?你打算根据什么上色?
-
我只是想获取每个数据,重建它(计算 .csv 中没有的零)并并排显示每个数据的箱线图,如下所示:@ 987654322@