I thought I'd give plotKML a try, as I need to visualize some gridded data, and Google Earth, combined with some tools from R (like plotKML), offers some great options. I hope.
I first tried the tutorial found at http://plotkml.r-forge.r-project.org/tutorial.php but found a few bumps. Hopefully someone will muster enough time to see what's going on.
I have installed all suggestede tools
library(plotKML)
## plotKML version 0.3-2 (2012-12-04)
## URL: http://plotkml.r-forge.r-project.org/
paths()
## Loading required package: RSAGA
## Loading required package: gstat
## Loading required package: sp
## Loading required package: spacetime
## Loading required package: shapefiles
## Loading required package: foreign
## Attaching package: 'shapefiles'
## The following object(s) are masked from 'package:foreign':
##
## read.dbf, write.dbf
## Loading required package: plyr
## Attaching package: 'plyr'
## The following object(s) are masked from 'package:plotKML':
##
## count
## Warning: running command '"C:\Program Files (x86)\SAGA-GIS/saga_cmd.exe"
## --version' had status 1
## Warning: running command '"C:\Program Files (x86)\SAGA-GIS/saga_cmd.exe"
## --version' had status 1
## Warning: running command '"C:\Program Files (x86)\SAGA-GIS/saga_cmd.exe"
## --version' had status 1
## Loading required package: animation
## Version: ImageMagick 6.7.0-0 2011-05-20 Q16 http://www.imagemagick.org
## Located FWTools from the Registry Hive: "C:\PROGRA~2\FWTOOL~1.7"
## Located Python from the Registry Hive: "Q:\Python25\\"
## gdalwarp
## 1 "C:\\PROGRA~2\\FWTOOL~1.7\\bin\\gdalwarp.exe"
## gdal_translate
## 1 "C:\\PROGRA~2\\FWTOOL~1.7\\bin\\GDAL_T~1.EXE"
## convert
## 1 "C:\\Program Files\\ImageMagick-6.7.0-Q16\\convert.exe"
## python saga_cmd
## 1 "Q:\\Python25\\python.exe" C:\\PROGRA~2\\SAGA-GIS\\saga_cmd.exe
Plotting a bubble chart.
data(eberg)
coordinates(eberg) <- ~X + Y
proj4string(eberg) <- CRS("+init=epsg:31467")
eberg <- eberg[runif(nrow(eberg)) < 0.2, ]
bubble(eberg["CLYMHT_A"])
## Error: missing values and NaN's not allowed if 'na.rm' is FALSE
Plotting a bubble plot in Google Earth.
plotKML(eberg["CLYMHT_A"]) # OK
Plot contours
data(eberg_contours)
plotKML(eberg_contours) # OK
plotKML(eberg_contours, colour = Z, altitude = Z) # OK
data(eberg_zones)
plotKML(eberg_zones["ZONES"]) # OK
plotKML(eberg_zones["ZONES"], altitude = runif(length(eberg_zones)) *
500) # OK
Plot gridded data. Something goes wrong. Any ideas?
data(eberg_grid)
gridded(eberg_grid) <- ~x + y
proj4string(eberg_grid) <- CRS("+init=epsg:31467")
data(SAGA_pal)
plotKML(eberg_grid["TWISRT6"], colour_scale = SAGA_pal[[1]])
## Plotting the first variable on the list
## KML file opened for writing...
## Reprojecting to +proj=longlat +datum=WGS84 ...
## rgdal: version: 0.8-5, (SVN revision 449) Geospatial Data Abstraction
## Library extensions to R successfully loaded Loaded GDAL runtime: GDAL
## 1.9.2, released 2012/10/08 Path to GDAL shared files:
## C:/Users/romunov/Documents/R/win-library/2.15/rgdal/gdal GDAL does not use
## iconv for recoding strings. Loaded PROJ.4 runtime: Rel. 4.7.1, 23
## September 2009, [PJ_VERSION: 470] Path to PROJ.4 shared files:
## C:/Users/romunov/Documents/R/win-library/2.15/rgdal/proj
## Error: 'z' must be a matrix
data(worldgrids_pal)
pal <- as.character(worldgrids_pal["corine2k"][[1]][c(1, 11, 13,
14, 16, 17, 18)])
plotKML(eberg_grid["LNCCOR6"], colour_scale = pal)
## Plotting the first variable on the list
## KML file opened for writing...
## Reprojecting to +proj=longlat +datum=WGS84 ...
## Error: 'z' must be a matrix
I have not included code beyond chapter Field photographs. It would seems up til here, everything works except when I try to plot on a grid (which is what I'm currently after).
My sessionInfo is
sessionInfo()
## R version 2.15.3 (2013-03-01)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
##
## locale:
## [1] LC_COLLATE=Slovenian_Slovenia.1250 LC_CTYPE=Slovenian_Slovenia.1250
## [3] LC_MONETARY=Slovenian_Slovenia.1250 LC_NUMERIC=C
## [5] LC_TIME=Slovenian_Slovenia.1250
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] rgdal_0.8-5 animation_2.1 RSAGA_0.93-2 plyr_1.8
## [5] shapefiles_0.6 foreign_0.8-52 gstat_1.0-10 spacetime_1.0-4
## [9] sp_1.0-6 plotKML_0.3-2 knitr_0.8
##
## loaded via a namespace (and not attached):
## [1] aqp_1.5 cluster_1.14.3 colorRamps_2.3
## [4] colorspace_1.2-1 dichromat_1.2-4 digest_0.5.2
## [7] dismo_0.8-11 evaluate_0.4.2 formatR_0.4
## [10] grid_2.15.3 Hmisc_3.9-3 intervals_0.14.0
## [13] labeling_0.1 lattice_0.20-13 munsell_0.3
## [16] parser_0.0-14 pixmap_0.4-11 plotrix_3.4-6
## [19] raster_2.1-16 RColorBrewer_1.0-5 Rcpp_0.10.2
## [22] reshape_0.8.4 scales_0.2.3 stringr_0.6.2
## [25] tools_2.15.3 XML_3.95-0.2 xts_0.9-3
## [28] zoo_1.7-9