Link

Networks in HTLM

Recently I gave a presentation about complexity in institutional networks for the Amazon in Colombia. For that I used the development version of the package reports. Which provides a nice and simple way to make fantastic and impressive presentations.

The core in the presentation were two networks representing a simple and a complex network using simulated data for government institutions in the Colombian Amazon. The nodes are: National parks, Environmental authorities, State governments, and Indian reserves.

The networks were simulated using the magic inside the package d3Network

A Simple Network

# Load RCurl package for downloading the data
library(bitops)
# library(RCurl)
library(d3Network)

datLinks<-read.csv(file="C:\\Users\\Diego\\Documents\\CodigoR\\Transparencia\\data\\MisLinks.csv",header=T)
datNodes<-read.csv(file="C:\\Users\\Diego\\Documents\\CodigoR\\Transparencia\\data\\MisNodes.csv",header=T)
datLinks$source<-as.numeric(datLinks$source)
datLinks$target<-as.numeric(datLinks$target)
datLinks$value<-as.numeric(datLinks$value)

network<-d3ForceNetwork(Links = datLinks, Nodes = datNodes, 
               Source = "source", Target = "target", 
               Value = "value", NodeID = "name", 
               Group = "group", width = 600, height = 300, 
               opacity = 0.9, 
               zoom = TRUE, 
                standAlone = FALSE,        
               # iframe = TRUE, #uncoment this line 
               linkColour = "#404040",    
              # file = "C:\\Users\\Diego\\Documents\\CodigoR\\Transparencia\\data\\ExampleGraph2.html" # uncoment if you want to save the html
                        )

Click to see the network

And the Complex Network

# Load RCurl package for downloading the data
library(bitops)
# library(RCurl)
library(d3Network)

datLinks<-read.csv(file="C:\\Users\\Diego\\Documents\\CodigoR\\Transparencia\\data\\MisLinks2.csv",header=T)
datNodes<-read.csv(file="C:\\Users\\Diego\\Documents\\CodigoR\\Transparencia\\data\\MisNodes2.csv",header=T)
datLinks$source<-as.numeric(datLinks$source)
datLinks$target<-as.numeric(datLinks$target)
datLinks$value<-as.numeric(datLinks$value)

network<-d3ForceNetwork(Links = datLinks, Nodes = datNodes, 
                        Source = "source", Target = "target", 
                        Value = "value", NodeID = "name", 
                        Group = "group", width = 600, height = 300, 
                        opacity = 0.9, 
                        # iframe = TRUE, #uncoment this line
                        linkColour = "#808080",
                        # file = "C:\\Users\\Diego\\Documents\\CodigoR\\Transparencia\\data\\ExampleGraph3.html"
                        )

Click to see the network

Move the mouse over the nodes. Click on it, drag and drop…

Impressive eh?

This post was made from R + knitr to WordPress.

Biodiversity by Colombian institutions

Maps of collected biodiversity by Colombian institutions

In a previous post I got the georeferenced data set of biodiversity from SIB Colombia using IAvH code. The data set is composed of 127 tables corresponding to the GBIF grid over Colombia.

Some tables still need some additional work to fix extra spaces, inconsistent characters and different encodings. But after some work, I put together all the tables. When plotting the data set, 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.

code chunk

The data set (bigtable) is 70 megas aprox. Pleas let me know if you are interested on it

require(ggmap)
require(raster)
require(rgeos)
#### load data set 252.944 records
bigtable <- read.csv(file = "data/sib_bigtable.csv", header = T, encoding = "UTF-8")

# get poligon Colombia
co <- getData("GADM", country = "CO", level = 1, download = TRUE)
co$NAME_1 <- iconv(co$NAME_1, "ISO_8859-2", "UTF-8")
col_depto <- fortify(co, region = "NAME_1")  # make compatible to ggplot2

# 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)

The first map. All points

A map showing all collection points. The points are transparent. So darker means more points in that location.

map1

The second map. Collected Where?

A map showing hexagonal bins with more collection points. Interesting: no hexagons means no collection in that place.

map2

The third map by institution

A map showing all the points. Colors by institution. It is hard to see the different institutions.

map3

The last map, wrapped by institution

This is slow, but worth…. meanwhile take a coffee. It shows the extend of each collection by institution.

map4

It is nice to see how the Herbario Nacional Colombiano (COL) is the most extensive collection in Colombia. Now I have to figure which collection or institution is 8200001422-01…

After some comments from @OigaMen and @Danipilze now I know that the code 8200001422-01 is part of the IAvH collection. It is their NIT. So for the next post I am going to fix that.

I had fun learning how to make and publish a blog posts from R + knitr to WordPress. Next posts will even more interesting, I am sure.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

A map of collected biodiversity by Colombian institutions

I was having fun paying with the package dismo dismo and GBIF data when I discovered that using IAvH code you can download all the data set for Colombian institutions. So I decided to play with it.

Some tables still need some additional work to fix extra spaces and inconsistent characters. Plotting this data set you can see where mainly Colombian researchers have collected biodiversity.

Th idea is that each blue point is a collection record. Image

From here you can get the R code

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.