我已经开始转换从基本R图形到格子图形。现在我有了一些数据和一个适合于这些数据的nls(),我正在试图将两者都绘制到一个图上。因此,作为一个简单的R基图形代码:
require(lattice)
# Data
V <- c(45.5513,57.9145,66.3092,72.3338,79.7007,92.5738,107.9735,153.7357,210.8857)
E <- c(-0.05403,-0.20890,-0.24562,-0.25644,-0.26019,-0.25213,-0.23181,-0.17106,-0.10860)
# Guesses
V0g <- 118.5614
E0g <- -0.2579124
B0g <- 0.004868107
Bp0g <- 4
# nls fit
birchfit <- nls(E ~ E0 + (9*V0*B0)/16 * ( ((V0/V)^(2/3)-1)^3*Bp0 + ((V0/V)^(2/3)-1)^2 * (6-4*(V0/V)^(2/3)) ),start=list(B0=B0g,V0=V0g,Bp0=Bp0g,E0=E0g))
# Plot
VV <- seq(V[1],tail(V,1),length=1000)
plot(V,E)
lines(VV,predict(birchfit,data.frame(V=VV)))现在,对于格子变体,我尝试这个,
VV <- seq(V[1],tail(V,1),length=1000)
print(xyplot(E ~ V,
panel=panel.xyplot(VV,predict(birchfit,data.frame(V=VV)),type="l")))然后我被告知(通过图表中间的文字)
Error using packet 1
'what' must be a character string or function发布于 2014-04-04 19:08:13
通过使用as.layer from latticeExtra包向同一个面板添加两个单独的图,我就能够实现我想要的结果。也许有更好的解决方案,但这对我有用。
require(latticeExtra)
...
VV <- seq(V[1],tail(V,1),length=1000)
plot1 <- xyplot(E ~ V)
plot2 <- xyplot(predict(birchfit,data.frame(V=VV)) ~ VV,type="l")
print(plot1 + as.layer(plot2))https://stackoverflow.com/questions/22845563
复制相似问题