Some projections from Vega-Lite do not work in Altair

Viewed 73

Based on the stack trace, I can see that Altair only accepts the following projections -

['albers', 'albersUsa', 'azimuthalEqualArea', 'azimuthalEquidistant', 'conicConformal', 'conicEqualArea', 'conicEquidistant', 'equalEarth', 'equirectangular', 'gnomonic', 'identity', 'mercator', 'naturalEarth1', 'orthographic', 'stereographic', 'transverseMercator']

However, I really wanted to have a polyhedral based projection, Cahill-Keyes specifically. After a bit of searching I found this page where I can see all the Vega-Lite projections - https://observablehq.com/@vega/vega-lite-cartographic-projections and it does have a few polyhedral projections.

However quite a lot of them do not seem to be supported in Altair. I am of the opinion that generally whatever is available in Vega-Lite can be done using Altair, so I am wondering why has Altair limited the number of projections?

2 Answers

Altair follows the Vega-Lite schema.

Vega-Lite lists supported projections in the ProjectionType definition; according to this, the allowed projection types are the following:

   "ProjectionType": {
      "enum": [
        "albers",
        "albersUsa",
        "azimuthalEqualArea",
        "azimuthalEquidistant",
        "conicConformal",
        "conicEqualArea",
        "conicEquidistant",
        "equalEarth",
        "equirectangular",
        "gnomonic",
        "identity",
        "mercator",
        "naturalEarth1",
        "orthographic",
        "stereographic",
        "transverseMercator"
      ],
      "type": "string"
    },

Altair will raise an error if you specify a projection that does not match one of these.

Using a bit of a hack you can use the vega-projection-extended project to get some more projections. There are some issues though, to quote Jeffrey Heer on the Observable site where you can see these projections in action -

Note that some projections may show artifacts due to a lack of clipping to the sphere of the globe. We're working on it!

Using Altair in a Jupyter Notebook you may not be able to use it. However, if you are sure of a certain projection, then you can export the HTML or the json spec and add the vega-projection-extended library and replace the existing projection with the one that you want. And voila, Vega-Lite will show the projection.

You can add the projection library as -

  <script src="https://cdn.jsdelivr.net/npm/vega-projection-extended@2"></script>

And in the vegaEmbed spec you can change the projection name as -

......."projection": {"type": "interruptedBoggs"}

enter image description here

Related