Hist2GE: Producing 3D histograms in Google Earth

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Hist2GE.R

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

1
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).

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, nils.arrigo@gmail.com 2012 EEB, the University of Arizona, Tucson

See Also

Shapes2GE GetEdges grid50

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
###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,
	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])
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)
  

Example output

####### Hist2GE
##### Start assigning observations to cells, please be patient...
Checked 5 % of observations...
Checked 10 % of observations...
Checked 15 % of observations...
Checked 20 % of observations...
Checked 25 % of observations...
Checked 30 % of observations...
Checked 35 % of observations...
Checked 40 % of observations...
Checked 45 % of observations...
Checked 50 % of observations...
Checked 55 % of observations...
Checked 60 % of observations...
Checked 65 % of observations...
Checked 70 % of observations...
Checked 75 % of observations...
Checked 80 % of observations...
Checked 85 % of observations...
Checked 90 % of observations...
Checked 95 % of observations...
Checked 100 % of observations...
##### Compute statistics and produce outputs, please be patient...
##### Done.
         lon     lat NumSpecies sp1 sp2 sp3
7555  3.2320 30.6460          1   1   0   0
7706  2.4040 32.6854          1   1   0   0
7999  2.0044 36.7768          1   1   0   0
8000  4.5208 36.7768          1   0   2   0
8001  7.0408 36.7768          1   0   3   0
8003 12.0772 36.7768          1   0   0   1
8006 19.6300 36.7768          1   0   0   1
8138 -2.6936 38.8216          1   1   0   0
8139 -0.1052 38.8216          1   1   0   0
8140  2.4868 38.8216          1   1   0   0
8141  5.0752 38.8216          1   0   3   0
8142  7.6636 38.8216          1   0   0   2
8143 10.2556 38.8216          1   0   0   2
8146 18.0244 38.8216          1   0   0   1
8275 -0.9080 40.8628          1   1   0   0
8276  1.7812 40.8628          1   4   0   0
8277  4.4668 40.8628          2   2   1   0
8278  7.1488 40.8628          1   0   2   0
8405 -7.4600 42.9022          1   2   0   0
8407 -1.9664 42.9022          1   3   0   0
8408  0.7840 42.9022          1   2   0   0
8409  3.5344 42.9022          2   4   1   0
8410  6.2776 42.9022          1   0   7   0
8411  9.0280 42.9022          1   0   0   4
8412 11.7784 42.9022          1   0   0   1
8413 14.5252 42.9022          1   0   0   1
8535 -2.8880 44.9470          1   1   0   0
8536 -0.0368 44.9470          1   2   0   0
8537  2.8252 44.9470          1   9   0   0
8538  5.6836 44.9470          1   0   9   0
8539  8.5348 44.9470          2   0   3   4
8540 11.3968 44.9470          1   0   0   3
8541 14.2552 44.9470          1   0   0   1
8658 -5.4440 46.9936          1   1   0   0
8659 -2.4920 46.9936          1   4   0   0
8660  0.4564 46.9936          1   3   0   0
8661  3.4084 46.9936          2   4   2   0
8662  6.3604 46.9936          1   0  10   0
8663  9.3088 46.9936          1   0   0   8
8664 12.2608 46.9936          1   0   0   4
8665 15.2092 46.9936          1   0   0   2
8777 -6.5888 49.0384          1   1   0   0
8778 -3.5144 49.0384          1   1   0   0
8779 -0.4364 49.0384          1   3   0   0
8780  2.6416 49.0384          1   3   0   0
8781  5.7160 49.0384          1   0   8   0
8782  8.7940 49.0384          2   0   2   7
8783 11.8720 49.0384          1   0   0  10
8785 18.0244 49.0384          1   0   0   1
8893 -1.4120 51.0832          1   3   0   0
8894  1.8028 51.0832          1   2   0   0
8895  5.0176 51.0832          1   0   8   0
8896  8.2324 51.0832          2   0   1   2
8897 11.4472 51.0832          1   0   0   3
9003  0.8884 53.1226          1   2   0   0
9004  4.2508 53.1226          1   0   2   0
9005  7.6132 53.1226          2   0   2   1
9006 10.9756 53.1226          1   0   0   3
9007 14.3452 53.1226          1   0   0   2
9008 17.7076 53.1226          1   0   0   2
9105 -7.1792 55.1692          1   1   0   0
9107 -0.1196 55.1692          1   3   0   0
9108  3.4084 55.1692          2   1   1   0
9109  6.9364 55.1692          1   0   3   0
9110 10.4680 55.1692          1   0   0   1
9206  0.8704 57.2086          1   2   0   0
9209 12.1240 57.2086          1   0   0   1
9210 15.8716 57.2086          1   0   0   1
9301  7.6528 59.2426          1   0   0   1
Warning message:
In if (species == 0 | length(species) == 0 | length(species) < nrow(coords)) species = rep("nospecies",  :
  the condition has length > 1 and only the first element will be used
####### Hist2GE
##### Start assigning observations to cells, please be patient...
Checked 5 % of observations...
Checked 10 % of observations...
Checked 15 % of observations...
Checked 20 % of observations...
Checked 25 % of observations...
Checked 30 % of observations...
Checked 35 % of observations...
Checked 40 % of observations...
Checked 45 % of observations...
Checked 50 % of observations...
Checked 55 % of observations...
Checked 60 % of observations...
Checked 65 % of observations...
Checked 70 % of observations...
Checked 75 % of observations...
Checked 80 % of observations...
Checked 85 % of observations...
Checked 90 % of observations...
Checked 95 % of observations...
Checked 100 % of observations...
##### Compute statistics and produce outputs, please be patient...
##### Done.
           lon     lat NumSpecies sp1 sp2 sp3
1347 -110.9276 31.9888          1   0   0   1
1517 -110.8448 32.0284          1   1   0   0
1519 -110.8844 32.0284          1   1   0   0
1523 -110.9672 32.0284          1   0   0   1
1606 -110.8844 32.0482          1   0   1   0
1690 -110.8268 32.0680          1   0   0   1
1691 -110.8448 32.0680          1   1   0   0
1699 -111.0068 32.0680          1   0   0   1
1702 -111.0644 32.0680          1   1   0   0
1703 -111.0860 32.0680          1   0   1   0
1777 -110.8268 32.0878          1   0   1   0
1779 -110.8664 32.0878          1   1   0   0
1781 -110.9060 32.0878          1   0   1   0
1785 -110.9852 32.0878          1   0   0   1
1787 -111.0248 32.0878          1   0   1   0
1791 -111.1076 32.0878          1   1   0   0
1792 -111.1256 32.0878          1   1   0   0
1865 -110.8448 32.1076          1   0   0   1
1869 -110.9276 32.1076          1   0   1   0
1870 -110.9456 32.1076          2   2   1   0
1874 -111.0248 32.1076          1   0   2   0
1875 -111.0464 32.1076          1   0   1   0
1876 -111.0644 32.1076          1   0   1   0
1877 -111.0860 32.1076          1   0   1   0
1880 -111.1472 32.1076          1   1   0   0
1956 -110.9276 32.1292          1   0   0   1
1961 -111.0248 32.1292          1   1   0   0
1964 -111.0860 32.1292          1   1   0   0
1966 -111.1256 32.1292          1   0   1   0
2035 -110.7656 32.1490          2   1   0   1
2038 -110.8268 32.1490          2   1   0   1
2040 -110.8664 32.1490          1   0   1   0
2044 -110.9456 32.1490          2   1   1   0
2045 -110.9672 32.1490          1   0   2   0
2046 -110.9852 32.1490          2   1   0   1
2048 -111.0248 32.1490          1   0   0   1
2050 -111.0644 32.1490          1   0   1   0
2054 -111.1472 32.1490          1   0   0   1
2121 -110.7476 32.1688          1   0   1   0
2125 -110.8268 32.1688          1   1   0   0
2126 -110.8448 32.1688          1   1   0   0
2130 -110.9276 32.1688          2   2   1   0
2131 -110.9456 32.1688          1   0   0   1
2133 -110.9852 32.1688          1   1   0   0
2134 -111.0068 32.1688          2   0   1   1
2135 -111.0248 32.1688          1   0   1   0
2136 -111.0464 32.1688          1   0   1   0
2137 -111.0644 32.1688          1   0   0   1
2139 -111.1076 32.1688          1   0   0   1
2140 -111.1256 32.1688          1   0   1   0
2143 -111.1868 32.1688          1   0   0   1
2210 -110.7872 32.1886          1   1   0   0
2211 -110.8052 32.1886          1   0   1   0
2212 -110.8268 32.1886          1   0   1   0
2213 -110.8448 32.1886          1   0   0   1
2214 -110.8664 32.1886          1   0   0   1
2217 -110.9276 32.1886          1   0   0   1
2218 -110.9456 32.1886          1   0   0   1
2219 -110.9672 32.1886          1   0   1   0
2221 -111.0068 32.1886          1   0   1   0
2223 -111.0464 32.1886          2   1   0   1
2224 -111.0644 32.1886          1   1   0   0
2230 -111.1868 32.1886          1   0   1   0
2300 -110.8448 32.2084          1   0   0   1
2302 -110.8844 32.2084          1   0   0   1
2303 -110.9060 32.2084          1   0   1   0
2305 -110.9456 32.2084          2   0   1   1
2306 -110.9672 32.2084          3   2   1   1
2309 -111.0248 32.2084          1   0   0   1
2315 -111.1472 32.2084          1   0   1   0
2384 -110.7872 32.2282          1   0   0   1
2386 -110.8268 32.2282          1   0   1   0
2387 -110.8448 32.2282          1   0   1   0
2389 -110.8844 32.2282          1   1   0   0
2390 -110.9060 32.2282          2   1   1   0
2391 -110.9276 32.2282          2   2   0   1
2392 -110.9456 32.2282          1   0   1   0
2393 -110.9672 32.2282          2   1   0   1
2394 -110.9852 32.2282          1   0   1   0
2395 -111.0068 32.2282          2   0   1   2
2397 -111.0464 32.2282          1   2   0   0
2398 -111.0644 32.2282          1   0   0   1
2401 -111.1256 32.2282          1   0   0   1
2474 -110.8448 32.2480          2   1   1   0
2475 -110.8664 32.2480          1   0   1   0
2476 -110.8844 32.2480          1   1   0   0
2477 -110.9060 32.2480          2   1   1   0
2478 -110.9276 32.2480          2   1   2   0
2479 -110.9456 32.2480          1   0   1   0
2480 -110.9672 32.2480          2   0   1   1
2481 -110.9852 32.2480          1   1   0   0
2482 -111.0068 32.2480          1   1   0   0
2483 -111.0248 32.2480          1   0   0   1
2484 -111.0464 32.2480          2   1   0   1
2490 -111.1652 32.2480          1   1   0   0
2556 -110.7476 32.2678          1   1   0   0
2557 -110.7656 32.2678          2   0   1   1
2558 -110.7872 32.2678          1   0   1   0
2559 -110.8052 32.2678          1   1   0   0
2562 -110.8664 32.2678          2   1   1   0
2563 -110.8844 32.2678          1   0   0   1
2564 -110.9060 32.2678          1   0   0   1
2565 -110.9276 32.2678          3   1   2   1
2567 -110.9672 32.2678          2   1   0   1
2569 -111.0068 32.2678          1   1   0   0
2570 -111.0248 32.2678          1   3   0   0
2572 -111.0644 32.2678          1   0   0   1
2573 -111.0860 32.2678          3   1   1   1
2646 -110.8052 32.2876          1   0   1   0
2648 -110.8448 32.2876          1   0   0   1
2649 -110.8664 32.2876          1   1   0   0
2651 -110.9060 32.2876          2   0   1   1
2653 -110.9456 32.2876          1   2   0   0
2654 -110.9672 32.2876          1   0   1   0
2655 -110.9852 32.2876          1   0   2   0
2656 -111.0068 32.2876          2   1   1   0
2657 -111.0248 32.2876          1   0   0   1
2734 -110.8268 32.3092          1   0   0   1
2736 -110.8664 32.3092          1   0   0   2
2738 -110.9060 32.3092          1   0   0   1
2739 -110.9276 32.3092          1   1   0   0
2740 -110.9456 32.3092          1   0   0   1
2741 -110.9672 32.3092          1   1   0   0
2746 -111.0644 32.3092          1   0   1   0
2747 -111.0860 32.3092          1   0   0   1
2824 -110.8844 32.3290          1   0   0   1
2827 -110.9456 32.3290          1   1   0   0
2828 -110.9672 32.3290          1   0   0   1
2829 -110.9852 32.3290          1   0   0   2
2830 -111.0068 32.3290          1   1   0   0
2831 -111.0248 32.3290          1   0   0   1
2832 -111.0464 32.3290          2   0   1   2
2833 -111.0644 32.3290          1   0   0   1
2834 -111.0860 32.3290          2   0   1   1
2907 -110.8052 32.3488          2   1   0   1
2911 -110.8844 32.3488          1   0   1   0
2912 -110.9060 32.3488          1   1   0   0
2915 -110.9672 32.3488          1   1   0   0
2918 -111.0248 32.3488          1   0   1   0
2919 -111.0464 32.3488          1   0   1   0
2995 -110.8268 32.3686          1   0   1   0
2999 -110.9060 32.3686          1   1   0   0
3000 -110.9276 32.3686          3   1   1   1
3006 -111.0464 32.3686          1   1   0   0
3007 -111.0644 32.3686          1   1   0   0
3082 -110.8268 32.3884          1   1   0   0
3083 -110.8448 32.3884          1   0   1   0
3088 -110.9456 32.3884          2   0   1   1
3091 -111.0068 32.3884          1   1   0   0
3178 -111.0068 32.4082          1   0   1   0
3182 -111.0860 32.4082          1   1   0   0
3252 -110.7476 32.4280          1   0   0   1
3256 -110.8268 32.4280          1   0   0   1
3259 -110.8844 32.4280          1   0   1   0
3363 -111.2264 32.4478          1   1   0   0
3435 -110.9276 32.4676          1   0   0   1
3436 -110.9456 32.4676          1   0   0   1
3521 -110.9060 32.4892          1   0   0   1
Warning message:
In if (species == 0 | length(species) == 0 | length(species) < nrow(coords)) species = rep("nospecies",  :
  the condition has length > 1 and only the first element will be used

R2G2 documentation built on May 29, 2017, 1:41 p.m.