2011-10-28 61 views
3

我有以下數據如何填充輪廓的顏色和在RSM寫軸名稱(R)

ct<-structure(list(Conc = c(50L, 100L, 150L, 50L, 100L, 150L, 50L, 
100L, 150L, 100L, 100L, 100L), kGy = c(10L, 10L, 10L, 15L, 15L, 
15L, 20L, 20L, 20L, 15L, 15L, 15L), CT.Y. = c(75L, 65L, 51L, 
87L, 93L, 89L, 81L, 86L, 78L, 92L, 93L, 92L)), .Names = c("Conc", 
"kGy", "CT.Y."), class = "data.frame", row.names = c(NA, -12L)) 

,我使用了響應面下述R代碼

library(rsm) 
ct.rsm<-rsm(CT.Y.~SO(Conc, kGy), data=ct) 
persp(ct.rsm, Conc ~ kGy, col=rainbow(50), theta=60, 
    phi=0, r = 3, d=1, border = NULL, ltheta = -135, lphi = 0 
    , shade = 0.75, zlab="CT",ylab="Concentration %", col.axis=37, font.lab=2,col.lab=33, 
    contour=("colors")) 

一個問題是,如何我可以在輪廓中填充顏色嗎? 和其他問題是關於軸標籤。對於X和Z軸的標籤,我可以給它貼上標籤,但是當我想要包含Y軸的標籤時,我會收到以下錯誤。

Error in persp.default(dat$x, dat$y, dat$z, xlab = dat$labs[1], ylab = dat$labs[2], : 
    formal argument "ylab" matched by multiple actual arguments 

希望有人能在這方面幫助我。 在此先感謝。 Response Surface Plot

+0

我試圖加載數據,但該結構不完整。通常這樣的問題是由於硬編碼「ylab」的包的作者所致,因此您需要破解該函數。我承認這有點奇怪,因爲你甚至沒有指定ylab,而該函數是'persp'的默認版本。 –

+0

對不起,代碼錯誤。請檢查我已包含ylab的更新代碼。響應曲面曲線看起來不錯,但我也需要輪廓中的顏色。 – Iftikhar

回答

4

我拼湊了一個數據的工作示例(沒有你的rownames)。從rsm函數返回的對象是類「rsm」「lm」,因此它由persp.lm處理。該函數具有硬編碼的ylab規範,並且不提供重標記。它可以被修復(令人費解的x和ylabs逆轉)。我在draw.cont.line改變了line功能多邊形,它說明在下面我的評論中提到進一步的努力聯繫起來端點需要:

persp.lm <- 
function (x, form, at, bounds, zlim, zlab, xlabs, col = "white", xlab=xlab, 
    contours = NULL, hook, atpos = 3, theta = -25, phi = 20, 
    r = 4, border = NULL, box = TRUE, ticktype = "detailed", ylab, 
    ...) 
{ 
    draw.cont.line = function(line) { 
     if (cont.varycol) { 
      cont.col = col 
      if (length(col) > 1) 
       cont.col = col[cut(c(line$level, dat$zlim), length(col))][1] 
     } 
     polygon(trans3d(line$x, line$y, cont.z, transf), col = cont.col, 
      lwd = cont.lwd) 
    } 
    plot.data = contour.lm(x, form, at, bounds, zlim, xlabs, 
     atpos = atpos, plot.it = FALSE) 
    transf = list() 
    if (missing(zlab)) 
     zlab = "" 
    facet.col = col 
    cont = !is.null(contours) 
    if (mode(contours) == "logical") 
     cont = contours 
    cont.first = cont 
    cont.z = cz = plot.data[[1]]$zlim[1] 
    cont.col = 1 
    cont.varycol = FALSE 
    cont.lwd = 1 
    if (is.character(contours)) { 
     idx = charmatch(contours, c("top", "bottom", "colors"), 
      0) 
     if (idx == 1) { 
      cont.first = FALSE 
      cont.z = plot.data[[1]]$zlim[2] 
     } 
     else if (idx == 2) { 
     } 
     else if (idx == 3) { 
      cont.varycol = TRUE 
      if (length(col) < 2) 
       col = rainbow(40) 
     } 
     else cont.col = contours 
    } 
    else if (is.list(contours)) { 
     if (!is.null(contours$z)) 
      cz = contours$z 
     if (is.numeric(cz)) 
      cont.z = cz 
     else if (cz == "top") { 
      cont.first = FALSE 
      cont.z = plot.data[[1]]$zlim[2] 
     } 
     if (!is.null(contours$col)) 
      cont.col = contours$col 
     if (!is.null(contours$lwd)) 
      cont.lwd = contours$lwd 
     if (charmatch(cont.col, "colors", 0) == 1) { 
      cont.varycol = TRUE 
      if (length(col) < 2) 
       col = rainbow(40) 
     } 
    } 
    for (i in 1:length(plot.data)) { 
     dat = plot.data[[i]] 
     cont.lines = NULL 
     if (!missing(hook)) 
      if (!is.null(hook$pre.plot)) 
       hook$pre.plot(dat$labs) 
     if (cont) 
      cont.lines = contourLines(dat$x, dat$y, dat$z) 
     if (cont && cont.first) { 
      transf = persp(dat$x, dat$y, dat$z, zlim = dat$zlim, xlab=ylab, 
       theta = theta, phi = phi, r = r, col = NA, border = NA, 
       box = FALSE) 
      lapply(cont.lines, draw.cont.line) 
      par(new = TRUE) 
     } 
     if (length(col) > 1) { 
      nrz = nrow(dat$z) 
      ncz = ncol(dat$z) 
      zfacet = dat$z[-1, -1] + dat$z[-1, -ncz] + dat$z[-nrz, 
       -1] + dat$z[-nrz, -ncz] 
      zfacet = c(zfacet/4, dat$zlim) 
      facet.col = cut(zfacet, length(col)) 
      facet.col = col[facet.col] 
     } 
     transf = persp(dat$x, dat$y, dat$z, xlab = xlab, 
      zlab = zlab, zlim = dat$zlim, ylab=ylab, 
      col = facet.col, border = border, box = box, theta = theta, 
      phi = phi, r = r, ticktype = ticktype) 
     if (atpos == 3) 
      title(sub = dat$labs[5]) 
     if (cont && !cont.first) 
      lapply(cont.lines, draw.cont.line) 
     if (!missing(hook)) 
      if (!is.null(hook$post.plot)) 
       hook$post.plot(dat$labs) 
     plot.data[[i]]$transf = transf 
    } 
    invisible(plot.data) 
} 

persp(ct.rsm, Conc ~ kGy, col=rainbow(50), theta=60, xlab="Something", 
    phi=0, r = 3, d=1, border = NULL, ltheta = -135, lphi = 0 
    , shade = 0.75, zlab="CT",ylab="Concentration %", col.axis=37, font.lab=2,col.lab=33, 
    contour=("colors")) 

enter image description here

+0

輪廓的顏色怎麼樣! – Iftikhar

+0

他們呢? (輪廓_are_着色。) –

+0

我猜OP正在底部尋找填充的輪廓。 – MYaseen208