2011-10-28 11 views
3

私は、次のしているデータ(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コードを使用しています輪郭の色を塗りつぶすことはできますか? とその他の質問は、軸のラベル付けに関するものです。 X軸とZ軸のラベルにはラベルを付けることができますが、Y軸のラベルを含める場合は、次のエラーが表示されます。

この点について私が何か助けてくれることを願っています。 ありがとうございます。 Response Surface Plot

+0

私はデータをロードしようとしたが、その構造が不完全です。通常、そのような問題はパッケージの作成者が「イラッブ」をハードコーディングしているために、その機能をハックする必要があります。私はあなたがylabを指定していないし、関数が 'persp'のデフォルトバージョンであるので、ちょっと奇妙だと認めます –

+0

コード内でごめんなさい。私がylabを含んでいる更新されたコードを確認してください。レスポンスサーフェスカーブは素敵ですが、輪郭にも色が必要です。 – Iftikhar

答えて

4

あなたのデータの実例をまとめました(あなたのrownamesはありません)。 rsm関数から返されるオブジェクトはクラス "rsm" "lm"であるため、persp.lmによって処理されます。この関数には、ハードコードされたylab仕様があり、再ラベル付けの規定はありません。それは固定することができます(xとylabsの困惑反転)。私は、ポリゴンにdraw.cont.lineline機能を変更し、それは以下の私のコメントで述べたように、エンドポイントをリンクするための更なる努力の必要性を示しています

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

彼らについてはどうですか? (輪郭は着色されています。) –

+0

OPはベースに塗りつぶした輪郭を探していますね。 – MYaseen208