Search code examples
juliageo

Shading a map with underlying data in Julia


I want to create a map of Germany where each state is shaded according to its gross domestic product. I know how to do this in R (and put the code below). Is there a possibility to do this in Julia in an equally simple way?

library(tidyverse)
library(ggplot2)
library(sf)

shpData = st_read("./geofile.shp")
GDPData <- read.delim("./stateGDP.csv", header=FALSE)
GDPData <- rename(GDPData,StateName=V1,GDP=V2)

GDPData %>%
  left_join(shpData) ->mergedData

ggplot(mergedData) + geom_sf(data = mergedData, aes(fill = BIP,geometry=geometry)) + coord_sf(crs = st_crs(mergedData))-> pBIP1

Solution

  • You'd load the Shapefile and use Plots to plot it. The ideomatic code is something like

    using Plots, Shapefile, CSV
    
    shp = Shapefile.shapes(Shapefile.Table("geofile.shp"))
    GDPData = CSV.read("stateGDP.csv")
    
    plot(shp, fill_z = GDPData.V2')
    

    Note the ' which transposes the values to a column vector - this will tell Plots to apply the colors to individual polygons.