How to create a simple map with custom "base" shapefile + data to plot on a separate CSV file

Hello, is it possible with Julia to plot a map based on a custom shapefile and a data file ? The simplest case is where we want to plot some “regional data” and the background colour represents the data, like in the attached image:

Typically I have a “base” shapefile describing the administrative regions I am interested in, with an ID in the attribute table, and a csv file with the data to plot (and obviously the ID). I then either load both in Qgis, make a joint between the two and then visualise the map based on the desired data or use R with the packages rgdal, cartography and ggplot2.

I has been looking for doing this by a while, but never found a practical way to do that in Julia…

2 Likes

That should definitely work with VegaLite.jl, I’m just not super familiar with the map stuff :slight_smile: Take a look at our map examples, this description on how to load custom shape files from JSON into a spec and maybe the geoshape documentation in the original vega-lite docs (there is probably a lot of other useful info there in other sections as well).

To add to what David said, there are also some more examples on making choropleth maps in U.S. Counties Choropleth.

For reading shapefiles there is GitHub - JuliaGeo/Shapefile.jl: Parsing .shp files in Julia. Through the GeoInterface it has plot recipes defined so you can do this:

using Plots, Shapefile
shp = Shapefile.shapes(Shapefile.Table("data.shp"))
plot(shp)

(I think you can color in the polygons yourself as well, don’t have an example at hand though).

Another project to watch is GitHub - JuliaPlots/GeoMakie.jl: Geographical plotting utilities for Makie.jl, which is still in early development, but shows promising visuals and performance for plotting both geospatial feature and raster data.

But indeed, if you first convert your data to GeoJSON/TopoJSON, then probably VegaLite will be the easiest.

2 Likes

I think you can just pass the values in to fill_z, or the colors to shapecolor.

Just a comment about data…
Some maps in GeoJSON / TopoJSON format can be found at Les fonds de carte disponibles - Khartis Documentation

The map you are looking for is available at

Khartis is an open source project from Sciences Po - Atelier de cartographie.

1 Like