newpacks <- c("pycno", "lattice", "Grid2Polygons", "rtop")
# install.packages(newpacks) # install the packages
lapply(newpacks, library, character.only = T)
## Loading required package: sp
## Loading required package: maptools
## Checking rgeos availability: TRUE
## Loading required package: rgeos
## rgeos version: 0.3-11, (SVN revision 479)
##  GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921 
##  Linking to sp version: 1.1-0 
##  Polygon checking: TRUE
## [[1]]
##  [1] "pycno"     "rgeos"     "maptools"  "sp"        "stats"    
##  [6] "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [11] "base"     
## 
## [[2]]
##  [1] "lattice"   "pycno"     "rgeos"     "maptools"  "sp"       
##  [6] "stats"     "graphics"  "grDevices" "utils"     "datasets" 
## [11] "methods"   "base"     
## 
## [[3]]
##  [1] "Grid2Polygons" "lattice"       "pycno"         "rgeos"        
##  [5] "maptools"      "sp"            "stats"         "graphics"     
##  [9] "grDevices"     "utils"         "datasets"      "methods"      
## [13] "base"         
## 
## [[4]]
##  [1] "rtop"          "Grid2Polygons" "lattice"       "pycno"        
##  [5] "rgeos"         "maptools"      "sp"            "stats"        
##  [9] "graphics"      "grDevices"     "utils"         "datasets"     
## [13] "methods"       "base"
x <- c("ggmap", "rgdal", "sp", "raster") # packages we assume are already installed
lapply(x, library, character.only = TRUE) 
## Loading required package: ggplot2
## rgdal: version: 1.0-4, (SVN revision 548)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
##  Path to GDAL shared files: /usr/share/gdal/1.11
##  Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.1-1
## [[1]]
##  [1] "ggmap"         "ggplot2"       "rtop"          "Grid2Polygons"
##  [5] "lattice"       "pycno"         "rgeos"         "maptools"     
##  [9] "sp"            "stats"         "graphics"      "grDevices"    
## [13] "utils"         "datasets"      "methods"       "base"         
## 
## [[2]]
##  [1] "rgdal"         "ggmap"         "ggplot2"       "rtop"         
##  [5] "Grid2Polygons" "lattice"       "pycno"         "rgeos"        
##  [9] "maptools"      "sp"            "stats"         "graphics"     
## [13] "grDevices"     "utils"         "datasets"      "methods"      
## [17] "base"         
## 
## [[3]]
##  [1] "rgdal"         "ggmap"         "ggplot2"       "rtop"         
##  [5] "Grid2Polygons" "lattice"       "pycno"         "rgeos"        
##  [9] "maptools"      "sp"            "stats"         "graphics"     
## [13] "grDevices"     "utils"         "datasets"      "methods"      
## [17] "base"         
## 
## [[4]]
##  [1] "raster"        "rgdal"         "ggmap"         "ggplot2"      
##  [5] "rtop"          "Grid2Polygons" "lattice"       "pycno"        
##  [9] "rgeos"         "maptools"      "sp"            "stats"        
## [13] "graphics"      "grDevices"     "utils"         "datasets"     
## [17] "methods"       "base"
lnd <- shapefile("../data/london_sport.shp")
cs <- rep(5000, 2) # cell size in x and y dimensions
cc <- bbox(lnd)[, 1] + (cs/2)
cd <- ceiling(diff(t(bbox(lnd)))/cs)  # number of cells per direction
grd <- GridTopology(cellcentre.offset = cc, cellsize = cs, cells.dim = cd)
grd
##                          x        y
## cellcentre.offset 506071.2 158350.8
## cellsize            5000.0   5000.0
## cells.dim             12.0     10.0
sp_grd <- SpatialGridDataFrame(grd, data=data.frame(id=1:prod(cd)))
summary(sp_grd)
## Object of class SpatialGridDataFrame
## Coordinates:
##        min      max
## x 503571.2 563571.2
## y 155850.8 205850.8
## Is projected: NA 
## proj4string : [NA]
## Grid attributes:
##   cellcentre.offset cellsize cells.dim
## x          506071.2     5000        12
## y          158350.8     5000        10
## Data attributes:
##        id        
##  Min.   :  1.00  
##  1st Qu.: 30.75  
##  Median : 60.50  
##  Mean   : 60.50  
##  3rd Qu.: 90.25  
##  Max.   :120.00
plot(sp_grd)
plot(lnd, add = T)

With rtop

rtpo <- createRtopObject(observations = lnd, formulaString = Pop_2001~1, predictionLocations = sp_grd, getRtopParams())
plot(rtpo$predictionLocations)

# rtopKrige(rtpo)