Plotting typological data with R

I made a tutorial on how to plot typological data (here from grambank) with R.

Here is the code.

library(ggplot2) # for creating nice plots
library(dplyr) # for manipulating data frames
library(sf) # for manipulation of shape files 
library(rnaturalearth) # for geographic data
library(rnaturalearthhires) # for high resolution geographic data
library(lingtypology) # for access to databases such as glottolog
library(viridis) # for colorblind-friendly color palettes


# Download to a temporary file
grambank057 <- tempfile(fileext = ".geojson")
download.file(
  "https://grambank.clld.org/parameters/GB057.geojson",
  grambank057
)


# Read the downloaded geoJson file with the sf library:
grambank  <- read_sf(grambank057)
head(grambank)

# create base map of Cameroon
cameroon <- ne_states(country = "Cameroon", returnclass = "sf")

# filter out all data points from grambank that are not in Cameroon
camerbank <- st_filter(grambank, cameroon)
head(camerbank)


#Grambank
ggplot() +
  geom_sf(data=cameroon)+
  theme_void() +
  geom_sf(data = camerbank, aes(fill=label), pch=21, size=2)+
  scale_fill_viridis(option="inferno", discrete=TRUE)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.