Plotly

Nice tool: plotly

Here is one plot generated from their tutorial:

Another plot I made based on Belgium population data (not sure they are still valid).

 

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
library(plotly)
library(maps)
py <- plotly(username='myname', key='mykey')
s <- "
Brussels  wikipedia article, Brussels Capital 	1,019,022 	50.85 / 4.349
Antwerp  wikipedia article, Flemish Region 	459,805 	51.22 / 4.403
Ghent  wikipedia article, Flemish Region 	231,493 	51.05 / 3.717
Charleroi  wikipedia article, Walloon 	200,132 	50.411 / 4.444
Li├Ęge  wikipedia article, Walloon 	182,597 	50.634 / 5.567
Bruges  wikipedia article, Flemish Region 	116,709 	51.209 / 3.224
Namur  wikipedia article, Walloon 	106,284 	50.467 / 4.867
Leuven, Flemish Region 	92,892 	50.88 / 4.701
Mons  wikipedia article, Walloon 	91,277 	50.454 / 3.952
Aalst, Flemish Region 	77,534 	50.936 / 4.035
"
 
d<-read.delim(textConnection(s),header=FALSE,sep="\t",strip.white=TRUE)
d[,1] <- unlist(lapply(d[,1],function(x){
    sp <- strsplit(as.character(x),' ')[[1]][1]
    gg <- strsplit(sp,',')[[1]][1]
}
                ))
d[,2] <- unlist(lapply(d[,2],function(x){
    sp <- as.numeric(gsub(',','',as.character(x)))
}))
 
d[,4] <- unlist(lapply(d[,3],function(x){
    sp <- strsplit(as.character(x),' / ')[[1]][1]
}
                       ))
 
d[,5] <- unlist(lapply(d[,3],function(x){
    sp <- strsplit(as.character(x),' / ')[[1]][2]
}
                       ))
 
 
beData <- d[,c(1,2,4,5)]
colnames(beData) <- c("Cities","Population","Latitude","Longitude")
 
#Create the hexagone map
borders <- list(x=map(regions="belgium")$x, 
               y=map(regions="belgium")$y,
                text='')
 
##Create the plotable city data
cities <- list(x= beData$Longitude, 
               y=beData$Latitude,
               text=paste(beData$Cities," - ",beData$Population, " inhab.",sep=""),
               type="scatter",
               mode="markers",
               marker=list("size"=sqrt(beData$Population/max(beData$Population))*100,
                   "opacity"=0.5))
 
#Plot the two traces
response = py$plotly(borders,cities)
 
#Access your plot.ly plot
browseURL(response$url)

Written by Jean-Baptiste Poullet

Data analyst – consultant – freelancer
Expert in Bigdata
Founder of RBelgium – R community in Belgium
Owner of the company Stat’Rgy
Contact me at jeanbaptistepoullet@statrgy.com

Posted in Uncategorized.

Leave a Reply

Your email address will not be published. Required fields are marked *