Skip to content

Instantly share code, notes, and snippets.

@agricolamz
Created November 27, 2024 14:40
Show Gist options
  • Save agricolamz/e1ea3143e17f4ded53f1cf56cdd777df to your computer and use it in GitHub Desktop.
Save agricolamz/e1ea3143e17f4ded53f1cf56cdd777df to your computer and use it in GitHub Desktop.
library(tidyverse)
df <- read_csv("https://raw.githubusercontent.com/LingConLab/rutul_dialectology/master/data/database.csv")
df |>
select(feature_title, feature_lexeme, value, settlement, value) |>
filter(!is.na(value),
value != "NO DATA",
value != "OTHER",
value != "\\?",
!(settlement %in% c("Tsudik", "Borch"))) |>
mutate(value = str_split(value, ";")) |>
unnest_longer(value) |>
mutate(value = str_squish(value)) |>
group_by(feature_title, feature_lexeme, settlement) |>
ungroup() |>
arrange(feature_title, feature_lexeme, settlement) |>
distinct(settlement, value, feature_title, feature_lexeme) |>
mutate(feature_lexeme = ifelse(is.na(feature_lexeme), "", feature_lexeme),
merged_value = str_c(feature_title, feature_lexeme, value)) |>
arrange(settlement) |>
select(settlement, merged_value) |>
group_by(merged_value) |>
mutate(value = 1,
shared_with_n_villages = sum(value)) |>
ungroup() |>
count(settlement, shared_with_n_villages) |>
ggplot(aes(shared_with_n_villages, settlement, label = n))+
geom_tile(aes(fill = n), colour = "white") +
geom_text(aes(label = n), colour = "white") +
scale_fill_gradient(low = "lightblue", high = "navy")+
coord_fixed()+
labs(x = "", y = "")+
scale_x_continuous(breaks = 1:12)+
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment