Learn R Programming

R2G2 (version 1.0-2)

Plots2GE: Georeferencing custom R plots into Google Earth

Description

Plots2GE: Places PNG R plots on Google Earth, as KML files.

Usage

Plots2GE(data, center, nesting = 0, customfun, goo = "Plots2GE.kml", testrun = FALSE)

Arguments

data
Dataset used for producing the plots (will be the input of your customfun, see below).
center
Matrix including the longitude(s) and latitude(s) of point(s) where to locate plots (decimal degrees). Must correspond to "data", with same number and ordering of observations.
nesting
Location-specific identifier, used to group the data into location-specific subsets and produce location specific plots. Must correspond to "data", with same number and ordering of observations.
customfun
User-defined function to produce the plots, see details.
goo
Name of the KML file to that will be saved into the working directory (use getwd() to find it).
testrun
Diagnositc mode. T (will run only at the screen, for checking purposes) or F (will produce actual plots as png files for Google Earth).

Value

A KML file is produced in the current working directory.

Details

The user needs to declare a function where the input is the "data" matrix, and the output is a plot. Plots2GE will then apply this function to any location-specific subset (the locations being defined using the "nesting" parameter). Any function is possible, just keep in mind that Plots2GE will apply it in a location-specific way

See Also

par plot

Examples

Run this code
## Preparing fake matrix
center = cbind(1:6, 1:6)
nesting = rep(1:3, each = 2)
fakeVar1 = rnorm(300, 0, 1)
fakeVar2 = rnorm(300, 0, 1)

fakematrix = data.frame(nesting, center, fakeVar1, fakeVar2)
fakematrix


## Preparing a user-defined function for producing the desired plots
myfun = function(input){
  plot(input[, 4], input[, 5], xlab='Xlab label', ylab='Ylab label', type = 'n', bty = 'n')
  points(input[, 4], input[, 5], col='red', pch = 16, cex = 2)
  }
 
 
## Producing KML - the easy way
Plots2GE(data = fakematrix,
	 center = fakematrix[, 2:3], 
	 nesting = fakematrix[, 1], 
	 customfun = myfun,
	 goo = "Plots2GE_V1.kml",
	 testrun = FALSE)

Run the code above in your browser using DataLab