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

**URL:** <https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580>\
**Category:** General Usage\
**Tags:** plotting, shapefile\
**Created:** [February 13, 2020, 2:56pm UTC](https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580 "2020-02-13T14:56:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 13, 2020, 2:56pm UTC](https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580/1 "2020-02-13T14:56:38Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/julialang/original/2X/0/027c5ca2449e52503c888ac4ba53f969b56a7330.png)

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…

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [February 13, 2020, 4:38pm UTC](https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580/2 "2020-02-13T16:38:17Z")

</div>

That should definitely work with VegaLite.jl, I’m just not super familiar with the map stuff 🙂 Take a look at our [map examples](https://www.queryverse.org/VegaLite.jl/dev/examples/examples_maps/), [this](https://discourse.julialang.org/t/how-to-make-vegalite-read-my-topojson-file/34546/6) description on how to load custom shape files from JSON into a spec and maybe the [geoshape](https://vega.github.io/vega-lite/docs/geoshape.html) documentation in the original vega-lite docs (there is probably a lot of other useful info there in other sections as well).

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [February 13, 2020, 4:53pm UTC](https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580/3 "2020-02-13T16:53:23Z")

</div>

To add to what David said, there are also some more examples on making choropleth maps in [U.S. Counties Choropleth](https://discourse.julialang.org/t/u-s-counties-choropleth/20845).

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

```julia
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](https://github.com/JuliaPlots/GeoMakie.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.

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [February 13, 2020, 6:12pm UTC](https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580/4 "2020-02-13T18:12:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scelles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scelles/32/220408_2.png) [@scelles](https://discourse.julialang.org/u/scelles)\
**Post date:** [March 3, 2020, 6:26pm UTC](https://discourse.julialang.org/t/how-to-create-a-simple-map-with-custom-base-shapefile-data-to-plot-on-a-separate-csv-file/34580/5 "2020-03-03T18:26:15Z")

</div>

Just a comment about data…  
Some maps in GeoJSON / TopoJSON format can be found at [Les fonds de carte disponibles - Khartis Documentation](https://www.sciencespo.fr/cartographie/khartis/docs/les-fonds-de-carte-disponibles/index.html)

The map you are looking for is available at

> <https://github.com/AtelierCartographie/Khartis/blob/master/public/data/map/FR-reg-2016/france.json>

Khartis is an open source project from [Sciences Po - Atelier de cartographie](http://www.sciencespo.fr/cartographie/).
