18Jan/16

Maps with R: slides

The other day, someone asked me if it was easy to do maps with R. My first thought was: “of course, it is”. I offered to prepare a few slides. I guess it was not that simple after all because one actually needs quite a lot of basic knowledge to be able to create its own map.

30Oct/14

Coordinates of “hot-spots”

Last week I uploaded a note about the paper @freakonometrics and I have submitted again after we added quite a few revisions. We have already made available most of the R code to reproduce our applications (on this GitHub repository). However, we did not share our method to obtain the coordinates of the “hot-spots” areas

22Oct/14

Kernel Density Estimation with Ripley’s Circumferential Correction

This is it! The revised version of a paper written with Arthur Charpentier has been submitted yesterday! It is untitled “Kernel Density Estimation with Ripley’s Circumferential Correction”. The paper is available on https://hal.archives-ouvertes.fr/hal-00725090.

19Apr/14

Maps with R

Last month, @freakonometrics posted a bunch of articles on his blog about the North pole (in French):

There are some maps on these articles that were produced using ggplot2 excellent package in R. We want to share our code here.

14Feb/14

Closest distance between countries

We sometimes need the distance between two countries in econometric models, for instance in gravity models. Bur for some countries, I think this measure could cause problem. Let’s take an example. If we want to model the volume of trade between country (i) and country (j), the economic theory says it will depend on the distance between (i) and (j). Let (i) be China, (j_1) Japan, and (j_2) India. The distance between (i) and (j_1) will be lower than between (i) and (j_2). Can we consider, though, that Japan is farther from China than India is?

So, rather than compute the distance between two head cities, it might be more accurate to compute the closest distance between the borders. If a border is shared by country (i) and country (j), then the distance should be zero.

25Nov/13

European Map using R

In this post, I will present a way to plot a European Union map using R. As you know, some countries are missing in the maps package. So, instead of working with that package, we will use the rworldmap one, available on CRAN. We will also need two more packages : ggplot2 and grid.

10Nov/13

Scale bar and North arrow on a ggplot2 map using R

After some research on the Internet, I gave up trying to find an R function to add a scale bar and a North arrow on a map, using ggplot().
So, I would like to present you what I have come up with.

The idea is really basic : we create two polygons for the scale bar, we add some text above, and we draw an arrow. That’s it. The only tricky thing here, is the way to obtain the coordinates of each element. An easy solution is to use the gcDestination function, from the maptools package.

27Aug/13

Carte R interactive

Depuis un moment, j’avais envie de créer une version un peu animée des cartes R. Il y a bien la possibilité d’exporter les cartes au format gif, mais il manque le côté où on devient acteur…

En cherchant sur la toile, on tombe rapidement sur le tutoriel de Sylvain Prévost qui est plutôt bien expliqué. En parcourant les commentaires, un certain Romain propose son lien avec une petite amélioration : l’affichage de résultats.

Ce qui me plaît dans la méthode employée pour faire cette carte, c’est que ça se base sur un fichier SVG. Or, bien évidemment, R propose d’exporter les graphiques au format SVG… Aussi, je vous propose aujourd’hui, à partir de R et d’un peu de bidouille, de créer une visualisation interactive (un peu) de la carte de France. Mes compétences en JavaScript étant nulles, le résultat n’est pas exceptionnel, mais il est facilement reproductible. Merci à @YoruNoHikage pour ses conseils avisés en javascript et en css.

27Aug/13

Points dans un cercle

Aujourd’hui, j’ai dû déterminer quels étaient les points géographiques (des stations météorologiques) se situant dans un cercle de centre et de rayon donnés. L’année dernière, j’avais tenté quelque chose, mais le résultat ne me plaisait pas vraiment. Je suis tombé sur une fonction qui m’avait échappé : gcDestination, du pakage maptools. Elle permet de retourner les coordonnées d’un point selon une distance et un angle donné.