Package ‘R2G2’ February 19, 2015 Type Package Title Converting R CRAN outputs into Google Earth. Version 1.0-2 Date 2012-03-09 Author Nils Arrigo Maintainer Nils Arrigo <[email protected]> Description Converting R CRAN outputs into Google Earth. License LGPL LazyLoad yes NeedsCompilation no Repository CRAN Date/Publication 2013-04-23 21:26:15 R topics documented: R2G2-package Axis2GE . . . curvy . . . . . Dots2GE . . . FancyPies . . . GetEdges . . . grid50 . . . . . Hist2GE . . . . Overlay2GE . . Phylo2GE . . . Pies2GE . . . . Plots2GE . . . PolyLines2GE . Shapes2GE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 4 5 5 6 7 8 11 12 13 15 16 20 22 1 2 Axis2GE R2G2-package Converting R CRAN outputs into Google Earth. Description This package includes a set of functions for producing basic and complex representations into Google Earth, via KML files. Details Package: Type: Version: Date: License: LazyLoad: R2G2 Package 1.0-1 2012-10-02 LGPL yes Basic features: functions to overlay R CRAN plots, dots, lines, custom and regular polygons into Google Earth. Complex features: histograms, pie-charts, contour plots and phylogenies into Google Earth. ## End-user functions: Phylo2GE - Producing 3D Phylogenies in Google Earth (requires ape and picante) Hist2GE - Producing 3D histograms in Google Earth Pies2GE - Producing 3D pie-charts in Google Earth PolyLines2GE - Producing 2D / 3D lines / polygons in Google Earth Shapes2GE - Producing 3D regular poly Plots2GE - Georeferencing custom R plots into Google Earth Dots2GE - Automated placement of observation Axis2GE - Automated placement of a Y-axis in Google Earth Overlay2GE - Automated placement of an overla ## Internal functions: curvy - Compute spherical coordinates of points along an arc GetEdges - Compute the edges of any n-sided regular polygon on a sphere FancyPies - Compute the edges of any regular n-sided figure in spherical coordinates and adds a pie cha Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson Axis2GE Adding a custom Y-axis in Google Earth. Description The function adds a Y-axis into Google Earth. Can be used to either generate a KML file or can be embedded into other R2G2 functions. Usage Axis2GE(coords, maxVal, maxAlt = 1e5, lwd = 2, apnd = TRUE, goo = "testAxis.kml") Axis2GE 3 Arguments coords Geographical position of the axis (latitude, longitude, in Decimal Degrees). maxVal The maximum value of the Y-axis (i.e. the largest observation). maxAlt The height (ceiling altitude) of the Y-axis into Google Earth (in meters). lwd Line widths used to draw the axis. apnd Should the Y-axis be appended to an existing KML that is under production (append = TRUE, to be used if Axis2GE is embedded in another KML generating function, see details) or should it be saved in its own KML file (append = FALSE)? goo To be provided if apnd = FALSE, name of the KML file to that will be saved into the working directory (use getwd() to find it). Details If apnd == TRUE, Axis2GE will provide a list containing the style (bloc1) and data (bloc2) sections of a standard KML file. These sections are then to be incorporated directly into the KML file being generated. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also contourLines Examples # Producing an axis as an additional KML file Axis2GE(coords = c(1,1), maxVal = 6698, maxAlt = 1e5, lwd = 2, apnd = FALSE, goo = "Demo_Axis2GE.kml") # Producing an axis, but storing the KML sections for later use DemoAxis = Axis2GE(coords = c(1,1), maxVal = 6698, maxAlt = 1e5, lwd = 2, apnd = TRUE) attributes(DemoAxis) #check out the contents of the obtained list DemoAxis$bloc1 #get the styles section DemoAxis$bloc2 #get the coordinates section 4 curvy curvy curvy - internal function to compute spherical coordinates of points along an arc Description An arc is defined by startDD and stopDD, the coordinates of its limit points (decimal degrees). New points are computed according to f, i.e. the fraction at which the desired point is located along the arc (f varies between 0 -> startDD to 1 -> stopDD) Usage curvy(f, startDD, stopDD) Arguments f Fraction of arc at which the desired point is located. f varies between 0 and 1, to generate points located between startDD and stopDD) startDD Geographical location of starting point of the arc (longitutde, latitude in decimal degrees). stopDD Geographical location of stoping point of the arc (longitutde, latitude in decimal degrees). Value The geographical coordinates of the desired point (longitude, latitude in decimal degrees). Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson References The original function was actually proposed by Rod Page on http://iphylo.blogspot.com/ Examples startDD = c(1, 5) stopDD = c(5, 1) curvy(0.5, startDD, stopDD) Dots2GE Dots2GE 5 Automated placement of observations, as dots, in Google Earth Description Produces KML files where observations are displayed as pushpins. Usage Dots2GE(coords, plnms, goo = "Dots2GE.kml") Arguments coords An array of geographical positions of observations (lines = observation, columns = lon & lat in decimal degrees). plnms Observations labels (text). goo Name of the KML file to that will be saved into the working directory (use getwd() to find it). Value A KML file is produced in the current working directory. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson Examples labels = c("A","B","C","D","E","F") coords = cbind(1:6, 1:6) Dots2GE(coords, labels, goo = "Dots2GE_V1.kml") FancyPies Computes the edges of any regular n-sided figure in spherical coordinates and adds a pie chart within it Description Provides coordinates for one pie chart, this function must be iterated to produce several pies. Usage FancyPies(center, obs, nedges = 3, radius = 5e4, orient = 0, diag = FALSE) 6 GetEdges Arguments center The geographical position of the pie as c(lon, lat) in decimal degrees. obs Vector of numerical and non-negative quantities that will be displayed as the pie slices (typically produced using table()). nedges The number of desired edges (3 -> triangle, 4 -> square, etc). radius The pie radius (in meters). orient The rotation factor of the fig (in degrees). diag Produce diagnostic plot for checking purposes (True or False). Details This function is wrapped within Pies2GE; see below. Value Provides an array of coordinates for drawing the pie chart as polygons (lines = points delimiting the pie sectors, columns = sector number, lon, lat in decimal degrees). Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also curvy GetEdges Pies2GE GetEdges Computing the edges of any n-sided regular polygon on a sphere Description Provides the edges coordinates for one n-sided regular polygon, corrected to account for the earth curvature. Usage GetEdges(center, radius, nedges, orient = 45) Arguments center The geographical position of the polygon as c(lon, lat) in decimal degrees. radius The polygon radius (in meters). nedges The number of edges (3 -> triangle, 4 -> square, etc). orient The rotation factor of the polygon (in degrees). grid50 7 Details Earth-curvature corrections are assuming a sphere, hence expect some deformations near to the poles. In addition, polygons that overlap with the poles will have missing values (i.e. when center coordinates + radius lead to overeach a pole). Value Provides an array of coordinates for the n-edges defining the desired polygon (lines = points delimiting the polygon, columns = lon, lat in decimal degrees). Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson References This function was retrieved as a PHP code from http://blog.thematicmapping.org/ This is an amazing blog; the R2G2 dvpt team thanks a lot Bjorn Sandvik for his outstanding implementations in Google Earth, and for sharing his great ideas and resources. GetEdges is actually an R implementation of his material. See Also Hist2GE Pies2GE Shapes2GE curvy grid50 Grids partitioning the surface of Earth into n equal areas. Description Sets of precomputed grids that partition the Earth’s surface into equal areas. Usage data(grid50) Details The available grids provide 50, 500, 5000, 10’000 and 20’000 equal area cells. The coordinates are given in radians. They can be converted into lat / lon decimal degrees using the code provided as an example. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson 8 Hist2GE References http://eqsp.sourceforge.net/ https://etna.mcs.kent.edu/vol.25.2006/pp309-327.dir/pp309-327.html Leopardi, P. "A partition of the unit sphere into regions of equal area and small diameter" (2006). Electronic Transactions on Numerical Analysis 25:309-327. Examples #Converting grid50 (radians) to usual decimal degrees data(grid50) Rad2DD = function(lon, lat){ lonDD = 360 * round((lon / (2 * pi)), 5) - 180 + 0.01 latDD = 180 * round(lat / pi, 5) - 90 + 0.01 cbind(lonDD, latDD) } grid50DD = Rad2DD(grid50[,2], grid50[, 3]) grid50DD #Converting decimal degrees to grid50 format (radians and properly centered) DD2Rad = function(lon, lat){ lonrad = (lon + 180) * pi/180 latrad = (lat + 90) * pi/180 cbind(lonrad, latrad) } grid50Rad = DD2Rad(grid50DD[ ,1], grid50DD[ ,2]) grid50Rad = data.frame("1", grid50Rad) #this step is only cosmetic and necessary for compatibily issues. grid50Rad Hist2GE Producing 3D histograms in Google Earth Description The current implementation produces Google Earth 3D histograms to i) count the number of distinct entities (e.g. species) per spatial unit (regional species diversity) or ii) count the number of occurrences of each entity per spatial unit (regional species abundance, detailled for each species). Usage Hist2GE(coords, species = 0, grid, goo, nedges, orient, maxAlt = 1e+05, colors = "auto", ...) Arguments coords An array of geographical positions of observations (lines = observation, columns = lon & lat in Decimal Degrees). species A corresponding vector qualitatively describing each observation (typically the taxonomic species identity). Hist2GE 9 grid The precomputed spatial grid to be used. Choose among grid50, grid500, grid5000, grid10000 or grid20000 to get the needed number of points on the earth surface, see examples below. Technically, any set of equally spaced points can be used as long as the provided grid complies with the format used in ?grid50. goo Name of the KML file to that will be saved into the working directory (use getwd() to find it). nedges The number of desired edges (3 -> triangle, 4 -> square, etc) for drawing the histograms. orient The rotation factor of histograms (in degrees). maxAlt The maximum height (ceiling altitude) of the histograms. colors Vector of colors corresponding to each species (one color per species), must be defined as hexadecimal values (as produced by usual R color palettes); leave to "auto" to get rainbow colors. ... Any additional arguments used internally. Details The computations are based on a set of precomputed grids, where each cells are equally spaced and cover equal earth areas. The cell locations were obtained using the EQSP matlab library (Paul Leopardi). Each observation is first assigned to its closest neighbouring cell, then Hist2GE outputs cell-based statistics. Value Two KML files (regional species richness and detailled species abundance) are produced in the current working directory. The function also outputs all these cell-based statistics as an array. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also Shapes2GE GetEdges grid50 Examples ###Using Hist2GE: the easy way #Produce fake species occurrences coords = cbind(rnorm(210, 6.32, 5), rnorm(210, 46.75, 5)) coords = coords[order(coords[,1]), ] species = rep(c("sp1", "sp2", "sp3"), each = 70) #Choose grid data(grid10000) # choose among grid50, grid500, grid5000, grid1000, grid20000 grid = grid10000 Hist2GE(coords = coords, species = species, 10 Hist2GE grid = grid, goo = "Jura", nedges = 6, orient = 45, maxAlt = 1e5) ###Using Hist2GE: using custom grids, when working at local scale (not accounting for earth curvature) #Produce fake species occurrences coords = cbind(rnorm(210, -110.954795, 0.1), rnorm(210, 32.228724, 0.1)) coords = coords[order(coords[,1]), ] species = rep(c("sp1", "sp2", "sp3"), 70) #Define the resolution (cell width, decimal degrees) cellwdth = 0.02 #And produce the desired grid automatically lonrange = range(coords[, 1]) if(sum(sign(lonrange)) == -2){ lonwdth = -cellwdth }else{ lonwdth = cellwdth } latrange = range(coords[, 2]) if(sum(sign(latrange)) == -2){ latwdth = -cellwdth }else{ latwdth = cellwdth } lonLeft = lonrange[1] - 0.01 * lonrange[1] lonRight = lonrange[2] + 0.01 * lonrange[2] latBottom = latrange[1] - 0.01 * latrange[1] latTop = latrange[2] + 0.01 * latrange[2] #Produce cell coordinates along lon and lat axes lonmarks = seq(lonLeft, lonRight, by = lonwdth) latmarks = seq(latBottom, latTop, by = latwdth) #Produce complete grid lonDD = rep(lonmarks, length(latmarks)) latDD = rep(latmarks, each = length(lonmarks)) gridDD = cbind(lonDD, latDD) #Convert it to radians centered and formated as in a "grid50" array DD2Rad = function(lon, lat){ lonrad = (lon + 180) * pi/180 latrad = (lat + 90) * pi/180 cbind(lonrad, latrad) } MyGridDD = cbind(lonDD, latDD) MyGridRad = DD2Rad(MyGridDD[, 1], MyGridDD[, 2]) Overlay2GE 11 MyGridRad = data.frame("Num" = 1:nrow(MyGridRad), "lon" = MyGridRad[, 1], "lat" = MyGridRad[, 2]) #this step is only cosmetic and necessary for compatibily issues. #Run Hist2GE Hist2GE(coords = coords, species = species, grid = MyGridRad, goo = "Tucson", nedges = 4, orient = 45, maxAlt = 5e3) Overlay2GE Automated placement of an overlayed image in Google Earth Description Produces a KML file from a set of coordinates (the NSEW limits of the image to overlay) and the image name. Usage Overlay2GE(coords, image = "/home/Images/myimage.jpg", goo = "Overlay2GE.kml") Arguments coords The image boundary coordinates (declared in decimal degrees with the following order: N, S, E and W) image The image name (if in working directory) or complete path of the image to map. At least *.jpg and *.png are supported by Google Earth. goo Name of the KML file to that will be saved into the working directory (use getwd() to find it). Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson 12 Phylo2GE Phylo2GE Producing 3D Phylogenies in Google Earth Description The function converts a phylogenetic tree and the corresponding geographical coordinates of its taxa into a KML that can be displayed into Google Earth. Usage Phylo2GE(geo, phy, resol = 0.1, minAlt = 1e+04, maxAlt = 2e+06, goo = "Phylo2GE.kml") Arguments geo Matrix of geographical centroids for each taxa. Lines = taxa, columns = species name (as in phylogeny), lon and lat in decimal degrees. phy Phylogenetic tree, as imported using read.tree (ape). resol Drawing resolution of arcs in the phylogeny. Each horizontal arc will be divided in 1/resol subarcs. minAlt Altitude of tips, as displayed in Google Earth (in meters). maxAlt Altitude of root ancestral node, as displayed in Google Earth (in meters). goo Name of the KML file to that will be saved into the working directory (use getwd() to find it). Details Phylo2GE matches the phy and geo objects, according to taxa names. This matching cares for differential sorting of the phy and geo objects. This property also allows focusing on tree subclades without needing to update the geo array. Value A KML file is produced in the current working directory. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson References KML conversions of phylogenies were first seen in Mesquite (http://mesquiteproject.org/mesquite/mesquite.html) and on Rod Page’s blog http://iphylo.blogspot.com/ See Also aggregate curvy Pies2GE 13 Examples # # # # # # # uncomment to use require(ape) require(picante) geo = data.frame(taxa = c("D", "E", "A", "B", "C", "F"), lon = c(9.291113, 23.18146, 75.274541, -8.653739, 11.622450, 12.622450), lat = c(8.774068, 4.581856, 48.078570, 10.966451, 28.722732, 29.722732)) geo # phy = "(((B:0.41,C:0.31):0.65,(D:0.21,E:0.11):0.75):0.85,A:0.51);" # phy = read.tree(text = phy) # Phylo2GE(geo, phy, resol = .05, goo = 'Phylo2GE.kml') Pies2GE Producing 3D pie-charts in Google Earth Description This function produces Google Earth 3D pie charts from geographical locations and frequency counts. The pie charts are displayed as regular n-sided polygons. Usage Pies2GE(center, obs, nesting = 0, goo = "Pies2GE.kml", colors = "auto", nedges = 20, orient = 0, maxAlt Arguments center An array of geographical position for pies (lines = pies, columns = longitude and latitude in decimal degrees). obs Array of numerical and non-negative quantities that will be displayed in each the pie slices. This is is typically a pivot table with lines = pies and columns = quantities to plot within pies. nesting Vector for grouping the pies / pie slices into handy folders / subfolders (optional). The groups must be designated as numbers. The default nesting (nesting = 0) groups pie slices according to their color. goo Name of the KML file to that will be saved into the working directory (use getwd() to find it). colors Vector of colors corresponding to each species (one color per species), must be defined as hexadecimal values (as produced by usual R color palettes); leave to "auto" to get rainbow colors. nedges The number of edges, defining the general shape of the pie (3 -> triangle, 4 -> square, etc). orient the rotation factor of the pie-chart (in degrees). maxAlt the height (ceiling altitude) of the pies. radius The pie radius (in meters). 14 Pies2GE Details The shape parameters (nedges, orient, radius and maxAlt) can be either a single value, that will be applied to all pies, or detailled values for each pie. Value A KML file is produced in the current working directory. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also curvy GetEdges FancyPies table aggregate Examples ## Preparing fake matrix center = cbind(1:6, 1:6) obs = cbind(1:6, 6:1, 1:6) #actual observations to be plot as a pie chart nesting = rep(1:3, each = 2) ## data to be pie-charted fakedata = cbind(nesting, center, obs) colnames(fakedata) = c("Group","Lon","Lat","Slice1","Slice2","Slice3") fakedata ## Producing KML - group pie slices according to color Pies2GE(center = fakedata[, 2:3], obs = fakedata[, 4:ncol(fakedata)], nesting = fakedata[, 1], goo = "Pies2GE_V1.kml", nedges = 20, orient = 0, maxAlt = 1e4, radius = 5e4) ## Producing KML - as before but also tweeking the shape / radius / height and color of each pie Pies2GE(center = fakedata[, 2:3], obs = fakedata[, 4:ncol(fakedata)], nesting = 0, goo = "Pies2GE_V2.kml", nedges = c(3, 3, 4, 4, 20, 20), orient = 0, colors = topo.colors(ncol(obs)), maxAlt = c(3e4, 3e4, 5e4, 5e4, 1e5, 1e5), radius = c(3e4, 3e4, 4e4, 4e4, 5e4, 5e4)) ## Producing KML - group pies according to external information (experimental) Pies2GE(center = fakedata[, 2:3], obs = fakedata[, 4:ncol(fakedata)], Plots2GE 15 nesting = fakedata[, 1], goo = "Pies2GE_V1.kml", nedges = 20, orient = 0, maxAlt = 1e4, radius = 5e4) 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). 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 Value A KML file is produced in the current working directory. 16 PolyLines2GE Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also par plot Examples ## 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) PolyLines2GE Producing 2D / 3D lines / polygons in Google Earth Description The function produces lines-based objects into Google Earth. This allows drawing open or closed polygons with custom shapes. Many parameters allow a fine tuning of the rendered objects. Usage PolyLines2GE(coords, nesting = 0, maxAlt = 10000, goo = "Lines2GE.kml", colors = "blue", extrude = 0, f PolyLines2GE 17 Arguments coords Array of geographical positions that define each line / polygon edges (latitude, longitude, in Decimal Degrees). The coordinates must be provided following counterclockwise order if you wish to draw closed polygons (this is actually required by Google Earth, in order to obtain a proper colors rendering). nesting Vector for identifying distinct lines / polygons, must correspond to "coords" and should be designated as numbers. The resulting lines / polygons are then stored into distinct folders. If used, this option expects that one color is defined for each nesting level (see color parameter below). maxAlt The height (ceiling altitude) of the lines / polygons (one maxAlt per line / polygon or one maxAlt for all lines / polygons). Note that point specific altitudes can be declared (maxAlt then includes the altitudes of all points in "coords") goo Name of the KML file to that will be saved into the working directory (use getwd() to find it). colors Vector of colors (if the nesting option is used, define one color per line / polygon; if no nesting is specified, the same color is applied on all lines / polygons). Must be defined as hexadecimal values (as produced by usual R color palettes); leave to "auto" to get rainbow colors extrude 3D rendering: 1 = extend polygon vertical faces to the ground, 0 = draw only polygon. fill Polygon rendering: T = fill polygon with "colors", F = draw polygon as lines, using "colors". lwd Lines rendering: line width (one width per line / polygon or one width for all lines / polygons). closepoly Polygon rendering: T = will close all polygons, F = keeps open polygons. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also contourLines Examples ###Drawing lines ###Drawing closed polygons #Prepare fake data pol1 = rbind(c(1,1,1e5), c(1,2,2e5), c(2,2,3e5), c(3,3,4e5)) pol2 = rbind(c(1,1,1e5), c(2,2,2e5), c(3,3,1e5), c(4,4,2e5)) coords = rbind(pol1, pol2) nesting = rep(c(1,2), each = 4) #data to be displayed fakedata = cbind(nesting, coords) 18 PolyLines2GE colnames(fakedata) = c("nesting", "Lon", "Lat", "Alt") fakedata #Producing KML - all points are at the same altitude PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Lines2GE_V1a.kml", maxAlt = 1e4, fill = FALSE, closepoly = FALSE, lwd = 2, extrude = 0) #Producing KML - all points, from a same line share the same altitude PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Lines2GE_V1b.kml", maxAlt = c(1e4, 1e5), fill = FALSE, closepoly = FALSE, lwd = 2, extrude = 0) #Producing KML - Each point has its own altitude PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Lines2GE_V1c.kml", maxAlt = fakedata[, 4], fill = FALSE, closepoly = FALSE, lwd = 2, extrude = 0) ###Drawing closed polygons #Prepare fake data pol1 = rbind(c(1,1), c(1,2), c(2,2), c(2,1)) pol2 = (2 * pol1) - 0.5 coords = rbind(pol1, pol2) coords = coords[ nrow(coords) : 1,] nesting = rep(c(1,2), each = 4) #data to be displayed fakedata = cbind(nesting, coords) fakedata #Producing KML - the easy way PolyLines2GE PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Poly2GE_V1.kml", maxAlt = 0, fill = FALSE, closepoly = TRUE, lwd = 2, extrude = 0) #Producing KML - the easy way, polygons at distinct heights PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Poly2GE_V1b.kml", maxAlt = c(1e4, 1e5), fill = FALSE, closepoly = TRUE, lwd = 2, extrude = 0) #Producing KML - with filled polygon PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Poly2GE_V2.kml", maxAlt = 0, fill = TRUE, closepoly = TRUE, lwd = 2, extrude = 0) #Producing KML - with polygon extruded from ground PolyLines2GE(coords = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", goo = "Poly2GE_V3.kml", maxAlt = c(1e4, 1e5), fill = TRUE, closepoly = TRUE, lwd = 2, extrude = 1) ###Drawing a contour plot using the PolyLines2GE function: #Prepare data data(volcano) lat = seq(1, 6, length.out = nrow(volcano)) lon = seq(1, 6, length.out = ncol(volcano)) #Get contour lines cont = contourLines(lat, lon, volcano, nlevels = 20) 19 20 Shapes2GE #Convert them into Lines2GE input format cont.data = NULL for(i in 1:length(cont)){ subs = cont[[i]] tmp = cbind(i, subs$x, subs$y) cont.data = rbind(cont.data, tmp) } #Produce KML PolyLines2GE(coords = cont.data[, 2:3], nesting = cont.data[, 1], colors = "auto", goo = "Contour2GE_V1.kml", maxAlt = seq(1e4, 1e5, length.out = length(cont)), fill = FALSE, closepoly = FALSE, lwd = 2, extrude = 0) Shapes2GE Producing 3D regular polygons in Google Earth Description This function produces 3D regular polygons in Google Earth. Usage Shapes2GE(center, nesting = 0, goo = "Shapes2GE.kml", nedges = 20, orient = 0, colors = "blue", maxAlt Arguments center nesting goo nedges orient maxAlt radius colors An array of geographical position for pies (lines = pies, columns = longitude and latitude in decimal degrees). Vector for grouping the shapes into handy folders / subfolders (optional). Must correspond to "center" and the groups should be designated as numbers. Name of the KML file to that will be saved into the working directory (use getwd() to find it). The number of edges, defining the general shape of the polygon (3 -> triangle, 4 -> square, etc). the rotation factor of the pie-chart (in degrees). the height (ceiling altitude) of the pies. The pie radius (in meters). Vector of colors (will correspond to nesting groups, so define one color per group, and not one color per shape), must be defined as hexadecimal values (as produced by usual R color palettes); leave to "auto" to get rainbow colors. Shapes2GE Value A KML file is produced in the current working directory. Author(s) Nils Arrigo, [email protected] 2012 EEB, the University of Arizona, Tucson See Also GetEdges, Hist2GE, Pies2GE GetEdges Hist2GE Pies2GE Examples ######Demo script #Preparing fake matrix center = cbind(1:6, 1:6) nesting = rep(1:3, each = 2) # data to be displayed fakedata = cbind(nesting, center) fakedata #Producing KML - the easy way Shapes2GE(center = fakedata[, 2:3], nesting = 1, colors = "#0000FFFF", goo = "Shapes2GE_V1.kml", nedges = 20, orient = 0, maxAlt = 1e4, radius = 5e4) #Producing KML - the very easy way Shapes2GE(center = fakedata[, 2:3], nesting = fakedata[, 1], colors = "auto", #just define your groups and let it get the colors goo = "Shapes2GE_V1b.kml", nedges = 20, orient = 0, maxAlt = 1e4, radius = 5e4) #Producing KML - one param per shape Shapes2GE(center = fakedata[, 2:3], nesting = c(1, 1, 2, 3, 3, 3), colors = c("#0F00FFFF","#00FF00FF","#FF0000FF"), #do it yourself goo = "Shapes2GE_V2.kml", nedges = c(3, 3, 4, 4, 5, 5), orient = 0, maxAlt = 1e4, radius = 5e4) 21 Index par, 16 Phylo2GE, 12 Pies2GE, 6, 7, 13, 21 plot, 16 Plots2GE, 15 PolyLines2GE, 16 ∗Topic Google Earth Dots2GE, 5 R2G2-package, 2 ∗Topic arc curvy, 4 ∗Topic geographical Phylo2GE, 12 ∗Topic google earth Hist2GE, 8 Phylo2GE, 12 ∗Topic histogram Hist2GE, 8 ∗Topic midpoints curvy, 4 ∗Topic phylogeny Phylo2GE, 12 ∗Topic points Dots2GE, 5 ∗Topic three dimension Phylo2GE, 12 R2G2 (R2G2-package), 2 R2G2-package, 2 Shapes2GE, 7, 9, 20 table, 14 aggregate, 12, 14 Axis2GE, 2 contourLines, 3, 17 curvy, 4, 6, 7, 12, 14 Dots2GE, 5 FancyPies, 5, 14 GetEdges, 6, 6, 9, 14, 21 grid10000 (grid50), 7 grid20000 (grid50), 7 grid50, 7, 9 grid500 (grid50), 7 grid5000 (grid50), 7 Hist2GE, 7, 8, 21 Overlay2GE, 11 22
© Copyright 2026 Paperzz