Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I import an SVG file in R ? [closed]

Tags:

r

svg

I have a map of France with the contour of French departments in an SVG file. I would like to import the data in R to draw a choropleth map. Is it possible ? What would be the best solution ?

like image 696
PAC Avatar asked Nov 08 '13 17:11

PAC


Video Answer


2 Answers

There's SVGMapping::loadSVG (at CRAN) -- I haven't tried it so can't speak to its quality.

Edit: might as well mention the sos package here, as it's really an indispensable tool for finding R packages and functions for the user.

like image 58
Carl Witthoft Avatar answered Oct 18 '22 20:10

Carl Witthoft


I guess it is possible. SVG is nothing more than a XML document. But why don't you use maps library?

library(maps)
map('france')

You can check:

>  map('france')$names
[1] "Nord"                                
[2] "Pas-de-Calais"                       
[3] "Somme"
...                         

for departments names, and paint individual departments like this:

colors[c(112, 114)] <- 'blue'
map('france', fill=T, col=colors)

enter image description here

See maps documentation for more.

like image 1
zero323 Avatar answered Oct 18 '22 21:10

zero323