# Shapes from geojson on geo map with Plotly

**URL:** <https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777>\
**Category:** Visualization\
**Tags:** geo, plotlyjs, map\
**Created:** [November 4, 2022, 2:05pm UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777 "2022-11-04T14:05:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lgo/32/48751_2.png) [@lgo](https://discourse.julialang.org/u/lgo)\
**Post date:** [November 4, 2022, 2:05pm UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777/1 "2022-11-04T14:05:35Z")

</div>

I want to plot a geojson with multiple geojsons as a geo map with Plotly. I tried to convert an [existing Python example](https://stackoverflow.com/questions/73372608/plotly-choropleth-not-drawing-any-polygons) to Julia but without success. The code below is just one example and I’ve also tested the same structure with different geojsons or not setting `featureidkey`. One thing I noticed was that the [Julia documentation on choropleth](https://plotly.com/julia/reference/choropleth/) does not mention a color option which is usually set in Python.

> using PlotlyJS, DataFrames
> 
> link = “[https://raw.githubusercontent.com/meherGill/geojson\_suburbs/main/suburbsModified.geojson](https://raw.githubusercontent.com/meherGill/geojson_suburbs/main/suburbsModified.geojson)”  
> geomap = choropleth(DataFrame(Postal = [“2603”,“2604”,“2605”]);geojson = link, locations=“Postal”, featureidkey = “properties.id”)  
> plot(geomap,Layout(landcolor=“#F0DC82”))

For context: As I’ve explained in a [previous post](https://plotly.com/julia/reference/choropleth/), I want to change the projection of the resulting map. Therefore, creating a [mapbox map](https://plotly.com/python/map-configuration/) is unfortunately not an option. I’ve also noticed that there are other packages for plotting shapes in Julia but none of them seem well maintained and offer the same range of formatting options.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 4, 2022, 2:20pm UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777/2 "2022-11-04T14:20:09Z")

</div>

> [@lgo](#):
>
> I’ve also noticed that there are other packages for plotting shapes in Julia but none of them seem well maintained and offer the same range of formatting options.

What is the problem with GMT.jl? Anything that I can help or, perhaps, improve?

---

<div class="post-metadata">

**Author:** ![lgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lgo/32/48751_2.png) [@lgo](https://discourse.julialang.org/u/lgo)\
**Post date:** [November 6, 2022, 9:28am UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777/3 "2022-11-06T09:28:11Z")

</div>

I want the function to be part of a package and therefore dependence on an external tool is a problem unfortunately.

---

<div class="post-metadata">

**Author:** ![lgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lgo/32/48751_2.png) [@lgo](https://discourse.julialang.org/u/lgo)\
**Post date:** [November 6, 2022, 11:17am UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777/4 "2022-11-06T11:17:15Z")

</div>

Realized the best way is to write a function myself. The code below uses the Proj package to translate lat/lon in x/y coordinates for different projections. Then I create shapes for plotting with Plots.

> using Plots, JSON, Proj  
> u = “country”  
> getShp\_json = JSON.parsefile(u \* “.geojson”)
> 
> trans = Proj.Transformation(“EPSG:4326”, “+proj=eck4 +axis=neu”)
> 
> allShp\_arr = Plots.Shape
> 
> for shp in collect(values(getShp\_json[“features”])), subShp in shp[“geometry”][“coordinates”], subSubShp in subShp  
> shp\_arr = map(z → trans(z[1], z[2]), subSubShp)  
> push!(allShp\_arr, Plots.Shape(shp\_arr))  
> end
> 
> Plots.plot(allShp\_arr,ticks = false, axis = false, legend = false, color = “#d9d9d9”)

![filename](https://global.discourse-cdn.com/julialang/original/3X/4/6/4677d561659a46c1d9eaa748ce1d9fb78baf2c90.png)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 6, 2022, 12:34pm UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777/5 "2022-11-06T12:34:39Z")

</div>

Just for comparison. This is one way of doing it with GMT

```julia
coast(DCW=(name=:UN150, pen=0.5, fill=:gray70), region=(-12,45,35,75),
         proj="eck4", frame=:none, show=true)

```

 ![GMTjl_tmp](https://global.discourse-cdn.com/julialang/original/3X/1/1/11e5b59c1f0e291b4c96b20ee83973264bee88fc.png)

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 10, 2022, 12:10pm UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777/6 "2022-11-10T12:10:55Z")

</div>

You can do something very similar entirely within `PlotlyJS` (`Colors` is just used for convenience):

```julia
using PlotlyJS
using Colors

geo = attr(scope="europe",
    projection=attr(type="eckert4",scale=0.9,rotation=attr(roll=2)),
    lonaxis=attr(range=[-15,60], showgrid=true),
    lataxis=attr(range=[35,72], showgrid=true),
    resolution="50", # alt. "110" or "50", in km/mm
    showland=true,
    showocean=true,
    oceancolor="rgb$(Colors.color_names["lightskyblue2"])",
    lakecolor="rgb$(Colors.color_names["lightsteelblue"])",
    landcolor="rgb$(Colors.color_names["lightgrey"])",
    countrycolor="rgb$(Colors.color_names["darkblue"])",
    countrywidth=1,
    subunitwidth=1,
)
layout = Layout(;title="Europe Levels", showlegend=false, geo=geo)
plot(scattergeo(), layout)

```

 ![test](https://global.discourse-cdn.com/julialang/original/3X/4/b/4b94f0e061cb3f94185c071b5d3a0d5464009965.png)
