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

Code
library(tidyverse)
library(leaflet)


line<-c(59.342549793703554, 18.057070698337594)
#line=c(60.01449406146719, 13.680270477312092)
df=tibble(line) %>%   t() 
colnames(df)<-c("lat","long")

df = df %>% as.data.frame() %>% tibble()
df=df %>% mutate(class = c(1))


#df=readr::read_csv("mysite/posts/a_image/bernerindustrier/calculations.csv")

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

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(paste(class)))

Creating a map

Leaflet is the package for you!