0

我是 R 新手,但在使用我尝试创建的函数时遇到了问题。

我的功能如下:

function3 <- function(data, x, y, z, a, c){
  GWRbandwidth <- gwr.sel(y ~ x + z, data=data,adapt=T)
  
  gwr.model <- gwr(y ~ x + z, data = data, adapt=GWRbandwidth, hatmatrix=TRUE, se.fit=TRUE)
  
  results <-as.data.frame(gwr.model$SDF)
  
  gwr.map<<- data
  
  gwr.map@data <<- cbind(data@data, as.matrix(results))
  
  map1 <- tm_shape(gwr.map) + tm_fill(a, n = 5, style = "quantile")  + tm_layout(frame = FALSE, legend.text.size = 0.5, legend.title.size = 0.6)
  
  map2 <- tm_shape(gwr.map) + tm_fill(z, n = 5, style = "quantile", title = "WB Coefficient") + tm_layout(frame = FALSE, legend.text.size = 0.5, legend.title.size = 0.6)
  
  map3 <- tm_shape(gwr.map) + tm_fill(c, n = 5, style = "quantile") + tm_layout(frame = FALSE, legend.text.size = 0.5, legend.title.size = 0.6)
  
  map4 <- tm_shape(gwr.map) + tm_fill(x, n = 5, style = "quantile", title = "Ue Coefficient") + tm_layout(frame = FALSE, legend.text.size = 0.5, legend.title.size = 0.6)
  
  grid.newpage()
  
  pushViewport(viewport(layout=grid.layout(2,2)))
  
  # prints a map object into a defined cell   
  print(map1, vp=viewport(layout.pos.col = 1, layout.pos.row =1))
  print(map2, vp=viewport(layout.pos.col = 2, layout.pos.row =1))
  print(map3, vp=viewport(layout.pos.col = 1, layout.pos.row =2))
  print(map4, vp=viewport(layout.pos.col = 2, layout.pos.row =2))
}

当我尝试像这样运行它时:

function3(OA.Census, OA.Census$White_British, OA.Census$Qualification, OA.Census$Unemployed, 'White_British', 'Unemployed')

我收到以下错误:

 Error: Fill argument neither colors nor valid variable name(s) 

如果有人可以帮助我,那就太好了!

4

0 回答 0