Search code examples
plotjuliavega-litecartography

Placing limits on edge of VegaLite map


I'm using VegaLite and VegaDatasets to show a Mercator projection of the world map, and plot a point at a specific latitude and longitude. So far, this works to produce the map:

data = DataFrame(x=[-45], y=[35])
scale = 100
world = dataset("world-110m")
@vlplot(width=700, height=500,
    config={
        view={stroke=:transparent}
    }
) +
@vlplot(data={values=world,
              format={type=:topojson,
                      feature="countries",
                     }},
        mark={type=:geoshape,
              stroke=:darkgray,
              strokeWidth=1},
        projection={type=:mercator,
                    scale=scale,
                    center=[0,35]},
    color={value="#eee"}
)

producing enter image description here

However, when I try to plot the point in the dataframe "data", I'm trying to set the domain in X and Y directions to (-180,180) and (-90,90), respectively:

+ @vlplot(data=data,
          :point,
          x = {:x, scale = {domain = (-180,180)}},
          y = {:y, scale = {domain = (-90,90)}},
  )

resulting in the following plot, where the domains are not at the edge of the horizontal and vertical axis. Additionally, the point seems to be plotted incorrectly within the defined grid:

enter image description here

Using the @vlplot syntax, how can I properly set up a latitude/longitude grid on my map, and plot a single point?


Solution

  • For plotting geoshape and geopoint in VegaLite, you should specify the coordinate by longitude and latitude. So your last code should be (projection should be included):

    + @vlplot(data=data,
              :point,
              longitude = :x,
              latitude = :y,
              projection={type=:mercator,
                        scale=scale,
                        center=[0,35]}
      )