Creating maps in R

news
code
analysis
Here we will dive deeper into the maps
Author

Jakob Johannesson

Published

May 6, 2022


Stockholm is the place to be

library(tidyverse)
library(leaflet)

line<-c(59.342549793703554, 18.057070698337594)
df=tibble(line) %>% 
  t() 
colnames(df)<-c("lat","long")
df = df %>% as.data.frame() %>% tibble()
df=df %>% mutate(class = c(1))


getColor <- function(df) {
  sapply(df$class, function(class) {
    if(class == 1) {
      "green"
    } else if(class == 2) {
      "orange"
    } else {
      "red"
    } })
}

icons <- awesomeIcons(
  icon = 'ios-close',
  iconColor = 'black',
  library = 'ion',
  markerColor = getColor(df)
)


#install.packages("leaflet")
#df
leaflet(data = df) %>% addTiles() %>%
  addAwesomeMarkers(~long, ~lat,icon=icons, label=~as.character(class))

Creating a map

Leaflet is the package for you!