我有物种和纬度/经度的data.frame(CAMANOC)。
我将一个函数和一个for循环应用于krige我的数据,并使用grid.arrange
在一个窗口中绘制所有绘图。
不幸的是,当我使用scale_fill_gradient2
时,颜色渐变似乎具有所有值的最小限制和最大限制。当scale_fill_gradient2
被掩盖时,每个人都会工作。
这是我的代码:
CAMANOCKrigeage <- function(CAMANOC,CAMANOC.grid2){
plotCAMANOC <- list() #Defining a list to save my maps
for (j in 1:8) #Calling species
{
var.exp <- variogram((CAMANOC[[j]])~1, CAMANOC)
var.mod=vgm(psill = 1, model = c("Exp", "Mat", "Sph"), nugget = 100, range = 2000,alpha = c(0, 45, 90, 135))
var.fit=fit.variogram(var.exp,var.mod)
krigeage = krige(formula = (CAMANOC[[j]])~1,CAMANOC,CAMANOC.grid2,model = var.fit)
krig.output=as.data.frame(krigeage)
names(krig.output)[1:4]<-c("long","lat","var1.pred","var1.var")
layer1 <- c(geom_tile(data=krig.output,aes(fill=var1.pred)))
plotCAMANOC[[j]] <- ggplot(data = krig.output,aes(x = long, y = lat)) +
geom_polygon(data = oceanfort, aes(x = long, y = lat, group = group), fill = "white") +
geom_polygon(data = coastlinefort, aes(x = long, y = lat, group = group), fill = "grey") +
geom_path(data = landfort, aes(x = long, y = lat, group=group)) +
ggtitle(names(CAMANOC)[j]) +
coord_cartesian(xlim = c(-6,1),ylim = c(48,51)) +
scale_fill_gradient2(name=bquote(atop("", ~cell.cm^-3)),
high="green", mid="blue", low="red",
space="Lab", midpoint = median(krig.output$var1.pred)) +
labs(x = "Longitude") +
labs(y = "Latitude") +
theme_bw() +
layer1
}
return(plotCAMANOC)
}
plotCAMANOC <- CAMANOCKrigeage(CAMANOC,CAMANOC.grid2)
do.call(grid.arrange,plotCAMANOC)
我很抱歉没有可复制的例子,我对此并不熟悉。