unable to understand code

anyone please guide what is the purpose of library(charlatan) and ch_name(5) in under mention code and if i want to replace latitude and longitude of my locations how i can do it in visualization stuff in leaflet? this code is working as it is but i am unable to understand how i can replace lat and long of my choice in leaflet function ?

library(sf)
library(dplyr)
library(leaflet)
library(charlatan)

somewhere in pakistan...

ingroup <- data.frame(lat=df1$i.lat, lon=df1$i.lon) %>%
mutate(name = ch_name(5)) %>%
st_as_sf(coords = c("lat","lon"), crs=4326)
ingroup

somewhere else in pakistan...

outgroup <- data.frame(lat=df1$lat,lon=df1$lon) %>%
mutate(name = ch_name(5)) %>%
st_as_sf(coords = c("lat","lon"), crs=4326)
outgroup

find the nearest neighbour: sf::st_nearest_feature (computationally very efficient)

ingroup <- ingroup %>%
mutate(nearest_out = outgroup$name[st_nearest_feature(., outgroup)]) %>%
mutate(label = paste0("ingroup: ", name, "
nearest outgroup is: ", nearest_out))

And now visualize the stuff!

leaflet() %>%
addTiles() %>%
addCircleMarkers(data = ingroup,
fillColor = "red",
stroke = F,
fillOpacity = .8,
popup = ~label) %>%
addCircleMarkers(data = outgroup,
fillColor = "blue",
stroke = F,
fillOpacity = .8,
popup = ~name)

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. Without it, I can only comment on charlatan, which is a package to generate fake data in various forms, for example, telephone numbers. ch_name is a function within that package that returns the number of names in its argument

library(charlatan)
ch_name(5)
#> [1] "Miss Suellen Pfannerstill DDS" "Assunta Dickens"              
#> [3] "Miah Graham"                   "Azaria Fadel-Johns"           
#> [5] "Issac Volkman"

Created on 2020-03-18 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.