how i can make cluster of one instorecustomer with 1 or 2 onlinecluster location depending upon distance i have plot both on map have to make cluster please help
library(sf)
#set.seed(100)
store=data.frame(lat=runif(1,33.45,33.75),long=runif(1,72.83,73.17))
onlineloc=data.frame(lat=runif(10,33.45,33.75),long=runif(10,72.83,73.17))
instore=data.frame(lat=runif(5,33.45,33.75),long=runif(5,72.83,73.17))
instorecustomer=round(instore,digits = 2)
plot(onlineloc,main="Online and instore customer loc",col=" red")
points(instore,pch=2)
points(store,pch=15)
legend(x=30,y=68,legend=c("Instore Customer","Online Customer","Store"),pch=c(2,1,15),col=c("black","red","black"))
#plot(onlineloc,main="Online customer loc",col=" red")
results=kmeans(onlineloc,5)
results
onlinecluster=results$centers[,]
onlinecluster=as.data.frame(onlinecluster)
onlinecluster=round(onlinecluster,digits = 2)
distance2=dist(onlinecluster)
round(distance2,digits = 2)
plot(hclust(distance2))
library(leaflet)
leaflet() %>% # for both locs on same map
addTiles() %>%
addPolylines(lng=onlinecluster$long,lat= onlinecluster$lat,color = "red",group = "1") %>%
#addMarkers(lat=onlineloc$lat,lng=onlineloc$long,popup = "Online Loc",group = "1") %>%
addCircleMarkers(lat=onlinecluster$lat,lng=onlinecluster$long,popup = "Online Loc",group = "1",radius=10,color = "green",clusterOptions = markerClusterOptions(color="red"))%>%
addPolylines(lng=instorecustomer$long,lat= instorecustomer$lat,color = "blue",group = "2") %>%
addMarkers(lng=instorecustomer$long,lat= instorecustomer$lat,popup = "instore customer",group = "2")%>%
addMarkers(lng=store$long,lat= store$lat,popup = "store ",group = "2")
its not creating reprex code when i copy complete code but create reprex of leaflet sepreate and above code seprately