Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rueter committed Sep 3, 2019
2 parents 89f18cd + 5c0cb27 commit dd8b259
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions R/functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# install.packages("tidyverse")
# install.packages("leaflet")

list.of.packages <- c("rmarkdown", "tidyverse", "leaflet")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

suppressPackageStartupMessages(library(tidyverse))
library(leaflet)

my_colors <-
c(
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#d62728",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#17becf",
sample(grDevices::colors()[!grepl("ivory|azure|white|gray|grey|black|pink|1",
grDevices::colors())])
)


read_mordva_file <- function(filename){

read_csv(filename) %>%
slice(-1) %>%
mutate(language = "Mordva") %>%
mutate(coordinate = str_trim(coordinate)) %>%
separate(coordinate, into = c("latitude", "longitude"), sep = ", ") %>%
mutate(latitude = as.numeric(latitude)) %>%
mutate(longitude = as.numeric(longitude))

}

make_mordva_map <- function(csv_file){

mordva_dataframe <- read_mordva_file(csv_file)

pal <- colorFactor({my_colors[1:length(unique(mordva_dataframe$dialect))]},
domain = mordva_dataframe$dialect)

leaflet(data = mordva_dataframe, width = "100%") %>%
addTiles() %>%
addCircleMarkers(popup = ~id,
color = ~pal(dialect),
radius = 5,
stroke = FALSE,
fillOpacity = 1,
lat = ~latitude,
lng = ~longitude) %>%
addLegend("bottomright", pal = pal, values = ~dialect,
title = "Dialect codes",
# labFormat = labelFormat(prefix = "$"),
opacity = 1
)

}

0 comments on commit dd8b259

Please sign in to comment.