library(Sleuth2)
mlr<-lm(ex1222$Buchanan2000~ex1222$Perot96*ex1222$Gore2000)
for (i in 0:3) {
assign(paste("betaHat", i, sep=""),
summary(mlr)$coeff[i+1,1])
}
x<-sort(ex1222$Perot96)
y<-sort(ex1222$Gore2000)
z1 <- outer(x, y, function(a,b) betaHat0+betaHat1*a+betaHat2*b+betaHat3*a*b)
nrz <- nrow(z)
ncz <- ncol(z)
# Create a function interpolating colors in the range of specified colors
jet.colors <- colorRampPalette( c("blue", "red") )
# Generate the desired number of colors from this palette
nbcol <- 100
color <- jet.colors(nbcol)
# Compute the z-value at the facet centres
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)
persp(x, y, z1, col=color[facetcol],theta=-30, lwd=.3,xlab="Perot 96", ylab="Gore 2000", zlab="Predicted Votes for Buchanan")
你好,
我正在尝试为上面的情节着色。我在想我想要更高的“z”值,颜色更深的红色(或任何颜色)。
任何有关如何实现这一目标的帮助将不胜感激。
此外,请随意提出不同的功能来实现这一点。
谢谢!
编辑....在查看 ?persp 上的示例后,我放置了我的新代码。我想改变颜色,但我对新情节的可读性不太满意