如何在R中绘制多个叠加等高线图

时间:2014-03-24 05:22:48

标签: r plot data-visualization

我有一个9个5x5矩阵的列表(cm),我希望使用9种方法中每种方法的不同颜色的叠加等高线图来显示。目前我可以使用透视图

绘制单个矩阵
persp(w1, w2, cm[[1]], theta = 30, phi = 30, expand = 0.5, col = "lightblue")

其中a和b是两个权重值,即来自

的独立变量
w1 <- seq(0.1, 0.5, 0.1)
w2 <- seq(0.1, 0.5, 0.1)

每个矩阵的各个值由函数返回(w1 * x + w2 * y + w3 * z)其中w3 = 1-(w1 + w2)

例如:

> cm[[1]]
          [,1]      [,2]      [,3]      [,4]      [,5]
[1,] 0.5032247 0.4924513 0.4816779 0.4709045 0.4601311
[2,] 0.4944491 0.4836757 0.4729023 0.4621289 0.4513555
[3,] 0.4856735 0.4749001 0.4641267 0.4533533 0.4425799
[4,] 0.4768979 0.4661245 0.4553511 0.4445777 0.4338043
[5,] 0.4681223 0.4573489 0.4465755 0.4358021 0.4250287

-----代码----

dataset <- read.table("composite_metric.log", header=T, sep=" ")

j = 1
df <- data.frame(cm = numeric(27))
while(j <= 27){  
  df$cm[j] <- mean(dataset[,j])
  j = j + 1
}

df <- t(df)

cm.i <- function(w.lb, w.dti, row, col){
  return(df[row,col]*w.lb + df[row,(col+9)]*(1-(w.lb+w.dti)) + df[row,(col+18)]*w.dti)
}

w_lb <- seq(0.1, 0.5, 0.1)
w_dti <- seq(0.1, 0.5, 0.1)
cm <- list()

col = 1
while(col <= 9){
  cm[[col]] = outer(w_lb, w_dti, cm.i, 1, col)
  col = col + 1
}

persp(w_lb, w_dti, cm[[1]], theta = 30, phi = 30, expand = 0.5, col = "lightblue")
filled.contour(w_lb, w_dti, cm[[1]])

0 个答案:

没有答案