Commits

Paul Hiemstra committed 137fd7e

Fixed bug in the ggplot of spatial cv residuals, updated examples.

Comments (0)

Files changed (1)

 # Automatically fits a variogram model to the data using autofitVariogram and performs
 # crossvalidation by calling krige.cv
 {
-	kr.cv = krige.cv(formula, input_data, model = autofitVariogram(formula, 
-														data_variogram, 
-														model = model, 
-														kappa = kappa,
-														fix.values = fix.values,
-														verbose = verbose,
-														GLS.model = GLS.model,
-                                                        start_vals = start_vals,
-                                                        miscFitOptions = miscFitOptions)$var_model,
-														...)
+	kr.cv = krige.cv(formula, input_data, 
+                      model = autofitVariogram(formula, 
+                                  data_variogram, 
+                                  model = model, 
+                                  kappa = kappa,
+                                  fix.values = fix.values,
+                                  verbose = verbose,
+                                  GLS.model = GLS.model,
+                                  start_vals = start_vals,
+                                  miscFitOptions = miscFitOptions)$var_model,
+                         verbose = verbose,
+						 ...)
 	kr.cv = list(krige.cv_output = kr.cv)
 	class(kr.cv) = "autoKrige.cv"
 	return(kr.cv)
 # Same as cv.compare.bubble, only now the plot is made using ggplot
 # instead of lattice. I find this version preferable.
 cv.compare.ggplot = function(objs, zcol = "residual", layout, col.names, addPoly = NULL) {
+  require(ggplot2, quietly = TRUE)
   objs = checkIfautokrige.cv(objs)
-  
+  if(!missing(col.names)) names(objs) = col.names
+
   # Build data for ggplot
   coornames = names(data.frame(coordinates(objs[[1]]$krige.cv_output)))
   dat = melt(lapply(objs, function(x) {
   if(!is.null(addPoly)) {
     require(gpclib)
     require(maptools)
-    if(!is.data.frame(addPoly)) addPoly = fortify(addPoly) else stop("addPoly should be SpatialPointsDataFrame")
+    if(inherits(addPoly, "SpatialPolygons")) addPoly = fortify(addPoly) else stop("addPoly should be SpatialPolygons* object")
     addPoly[[zcol]] = min(dat[[zcol]])
     addPoly[[zcol_abs]] = min(dat[[zcol_abs]])
-    ggobj = ggobj + geom_path(aes(x = long, y = lat, group = group), color = "lightgrey", size = 0.5, data = addPoly, legend = FALSE)
+    ggobj = ggobj + geom_path(aes_string(x = "long", y = "lat", group = "group"), color = "lightgrey", size = 0.5, data = addPoly, legend = FALSE)
   }
   return(ggobj + geom_point())
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.