In a previous post I got the georeferenced data set of biodiversity from SIB Colombia using IAvH code. The data set is composet of 127 tables corresponding to the GBIF grid.
Some tables still need some additional work to fix extra spaces and inconsistent characters. But after some work, I put together all the tables. When plotting the data, you can see where Colombian researchers have mostly collected biodiversity.
This time I want to see the use of ggplot2 and ggmaps to discover the contribution of each institution.
The data set is 70 megas aprox.
require(ggmap)
Loading required package: ggmap
Loading required package: ggplot2
require(raster)
Loading required package: raster
Loading required package: sp
#### load data set 252.944 records
bigtable <- read.csv(file = "data/sib_bigtable.csv", header = T)
# get poligon Colombia
co <- getData("GADM", country = "CO", level = 1, download = TRUE)
col_depto <- fortify(co, region = "NAME_1") # make compatible to ggplot2
Loading required package: rgeos
rgeos version: 0.2-17, (SVN revision 392) GEOS runtime version:
3.3.6-CAPI-1.7.6 Polygon checking: TRUE
locat = as.vector(bbox(co))
ncmap = get_map(location = locat, source = "stamen", maptype = "toner", zoom = 6)
# ggmap(ncmap) not nice
mapbase <- ggplot(col_depto, aes(long, lat, group = group)) + geom_polygon(fill = "grey60") +
coord_equal() + geom_path(color = "grey")
mapbase2 <- ggplot(col_depto, aes(long, lat, group = group)) + geom_polygon(fill = "White ") +
coord_equal() + geom_path(color = "grey")
map1 <- mapbase2 + geom_point(aes(x = lon, y = lat, group = TRUE), data = bigtable,
size = 1.5, alpha = 1/20) + theme(legend.position = "right") + guides(guide_legend((title = NULL)))
map2 <- mapbase + geom_point(aes(x = lon, y = lat, group = FALSE), size = 1,
data = bigtable, alpha = I(0.25), colour = "steelblue") + stat_binhex(aes(x = lon,
y = lat, group = FALSE), size = 0.5, binwidth = c(0.5, 0.5), alpha = 2/4,
data = bigtable)
map3 <- mapbase + geom_point(aes(x = lon, y = lat, group = TRUE, colour = factor(institution)),
data = bigtable, size = 2, alpha = 1/2) + theme(legend.position = "right")
map4 <- mapbase + geom_point(aes(x = lon, y = lat, group = FALSE), size = 0.5,
data = bigtable, colour = "red") + facet_wrap(~institution, ncol = 6)
A map showing all collection points. The points are transparent. So darker means more points in that location.
map1
A map showing hexagonal bins with more collection points. Interesting: no hexagons means no colecction in that place.
map2
A map showing all the points. Colors by institution.
map3
This is slow, but worth…. meanwhile take a coffee.
map4
After some coments from @OigaMen and @Danipilze the code 8200001422-01 is part of the IAvH collection. So for the next post I am going to fix that.
I had fun learning how to publish blog posts from R + knitr to WordPress. Next posts will even more interesting, I am sure.