本文介绍了如何在RSM(R)中填充轮廓颜色和写入轴名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有以下数据: ct 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)),Name = c(Conc kGy,CT.Y.),class =data.frame,row.names = c(NA,-12L)) 我正在使用以下R代码作为响应表面 库(rsm) ct.rsm persp(ct.rsm,Conc_kGy,col = rainbow(50) ,θ= 60, phi = 0,r = 3,d = 1,border = NULL,ltheta = -135,lphi = 0 ,shade = 0.75,zlab =CT 浓度%,col.axis = 37,font.lab = 2,col.lab = 33, contour =(colors)) 一个问题是,我如何填充轮廓的颜色? 和其他问题是关于轴标签。对于X和Z轴的标签,我可以给它贴上标签,但是当我想要包含Y轴的标签时,我收到以下错误消息。 在persp.default错误(dat $ x,dat $ y,dat $ z,xlab = dat $ labs [1],ylab = dat $ labs [2],:形式参数ylab由多个实际参数匹配 希望有人可以在这方面帮助我谢谢 解决方案我把你的数据拼凑在一起(没有你的rownames)。从rsm函数返回的对象是类rsmlm,所以它被persp.lm处理。这个函数有一个硬编码的ylab规范,并且没有提供重标记,它可以被修正(令人困惑的是x和ylabs的逆转),我改变了行函数。 draw.cont.line 改为多边形,它说明需要进一步努力来链接endp我的评论如下: 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。如果(长度(col)>> 1) cont.col = col [cut(c(line $ level,dat $ zlim),length(col))] [1] } polygon(trans3d(line $ x ,行$ y,cont.z,transf),col = cont.col, lwd = cont.lwd)} plot.data = contour.lm(x,form,at (blab)) zlab = atpos = atpos, (轮廓)==逻辑) cont =轮廓继续first = cont cont.z = cz = plot.data [[1]] $ zlim [1] cont.col = 1 cont.varycol = FALSE cont。 lwd = 1 if(is.character(contour)){ idx = charmatch(contour,c(top,bottom,colors), 0) if 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 = contour } else if(is.list(contour)){$ b $如果(is.numeric(cz)) cont.z = cz else if(!is.null(contours $ z)) cz = contours $ z if (cz ==top){ cont.first = FALSE cont.z = plot.data [[1]] $ zlim [2] } if(如果(!is.null(轮廓线$ lwd)) cont.lwd =轮廓线$ lwd $ b(等值线$ col)) cont.col =等值线$ col $ b if(charmatch(cont.col,colors,0)== 1){ cont.varycol = TRUE if(length(col) col =彩虹(40)} } (1:长度(plot.data)){ dat = plot.data [[i]] cont.lines = NULL if(!missing(hook)) if(!is.null(hook $ pre.plot)) hook (续) 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) ti (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 } 不可见(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 =浓度%,col.axis = 37,font.lab = 2,col。 lab = 33, contour =(colors)) I have following datact<-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))And i am using following R code for response surfacelibrary(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"))One question is that how can i fill the colors in contours?and other question is about the axes labeling. For label of X and Z axes i can label it, but when i want to include the label of Y-axis, i receive following error.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 argumentsHope that some one can help me in this regard.Thanks in advance. 解决方案 I pieced together a working example of your data (without your rownames). The object returned from the rsm function is classes "rsm" "lm", so it gets handled by persp.lm. That function has a hard-coded ylab specification and no provision for relabeling. It can be fixed (with a puzzling reversal of x and ylabs). I changed the line function in draw.cont.line to polygon and it illustrates the need for further efforts to link up the endpoints as mentioned in my comment below: 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")) 这篇关于如何在RSM(R)中填充轮廓颜色和写入轴名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 10:35