2016-11-27 13 views
-1

xy.plots 상단에 몇 가지 변형 모델을 표시하려고합니다. panel.plots은 대응하는 서브 플로트에 추가하려는 행 목록을 제외하고 모두 작동합니다.R 격자 팩키지로 라인 목록을 그려야합니다.

require(gstat) 
require(sp) 
data(meuse) 
names(meuse) 
#make directional variograms 
b<-variogram(log(zinc)~1, meuse, alpha = c(0, 45, 90, 135)) 
#split the variogram data by direction 
a<-lapply(1:length(unique(b$dir.hor)), 
      function(i) subset(b, grepl(unique(b$dir.hor)[[i]], b$dir.hor))) 
#get the model fit parameters for each directional variogram 
a<-lapply(1:length(unique(b$dir.hor)), 
      function(i) fit.variogram(a[[i]], vgm(0.5,"Exp", 1200, 0.5))) 
#generate model data for the directional variograms 
a<-lapply(1:length(a), function(i) 
    variogramLine(a[[i]], maxdist=1500)) 

#plot 
require(lattice) 
plot(b, ylim=c(0,1.2), xlim=c(0,1500), cex=1.5, 
    panel = function(x, y, ...) {panel.xyplot(x, y, ...) 
            panel.abline(v=1000, lwd=1, lty=3, col=2) 
            panel.lines(a[[i]], lwd=2, lty=2, col=4) 
    }) 

그것이 목록이 (플롯 디스플레이에 오류가 표시)이기 때문에 플롯의 마지막 인수는 작동하지 않습니다, 라인의 목록 격자으로 그려되어야하는지 확실하지. 도움을 받으실 수 있습니다!

+1

http://stackoverflow.com/help/mcve –

+2

@ 해킹-R에서 언급 한 바와 같이, 작업 예제를 제공하시기 바랍니다. 'meuse' 데이터는'library (sp)'FWIW에 있습니다. –

+0

@ RomanLuštrik done – ToNoY

답변

0

packet.number() 또는 panel.number()을 사용하면 현재 패널의 ID를 찾을 수 있습니다. 귀하의 예는 실패한 것처럼 제대로 작동하도록 몇 가지 변경 사항을 부과했습니다.

library(gstat) 
library(sp) 
data(meuse) 

# make directional variograms 
b <- variogram(log(zinc) ~ x + y, meuse, alpha = c(0, 45, 90, 135)) 

# split the variogram data by direction 
a <- lapply(1:length(unique(b$dir.hor)), 
      function(i) subset(b, grepl(unique(b$dir.hor)[[i]], b$dir.hor))) 

# get the model fit parameters for each directional variogram 
a <- lapply(1:length(unique(b$dir.hor)), 
      function(i) fit.variogram(a[[i]], vgm(0.5, "Exp", 1200, 0.5))) 

# generate model data for the directional variograms 
a <- lapply(1:length(a), function(i) variogramLine(a[[i]], maxdist = 1500)) 

# plot 
require(lattice) 
plot(b, ylim = c(0, 1.2), xlim = c(0, 1500), cex = 1.5, 
    panel = function(x, y, ...) { 
     panel.xyplot(x, y, ...) 
     panel.abline(v = 1000, lwd = 1, lty = 3, col = 2) 
     panel.lines(a[[packet.number()]], lwd = 2, lty = 2, col = 4) 
    }) 

Imgur