I am computing a central warehouse problem and need help to visualize the result.
I have a dataset with coordinates for local warehouses which I have then made a clustering in kmeans() which provide coordinates for the central-warehouse locations.
In total there are 9 clusters, so k=9. And there are a total of 552 local-warehouses.
I would like to show a plot with different colors based on which cluster (central-warehouse) each local-warehouse belong to. And show the index of the cluster in a legend.
To set the colors I use the palette() and add color to have a total of 9 different colors.
Using the code in #1# I get the result I want but without the legend. Using the code in #2# I get the legend but in wrong colors and not correct "format" of legend.
cc <- palette()
palette(c(cc,"purple"))
palette()
#1#
get_map("Mexico", zoom = 5) %>% ggmap()+
geom_point(data = Datafor_k_9, aes(x = `CW-lon`, y = `CW-lat`), col=Datafor_k_9$BelongToK, size = 3, shape=8)+
geom_point(data = Datafor_k_9, aes(x = `LW-lon`, y= `LW-lat`), col=Datafor_k_9$BelongToK, size=1)
p <- ggmap(get_googlemap("Mexico",zoom = 5,
maptype ='terrain',
color = 'color'))
p+geom_point(data = Datafor_k_9, aes(x = `CW-lon`, y = `CW-lat`,col=Datafor_k_9$BelongToK), size = 4,shape=8)+
geom_point(data = Datafor_k_9, aes(x = `LW-lon`, y= `LW-lat`, col=Datafor_k_9$BelongToK), size=1)
theme(legend.position = "right")
What am I doing wrong?
The data is combined in a single df called "Datafor_k_9".
The coordinates for local-warehouse is called "LW-lon"/"LW-lat" and for central-warehouse "CW-lon"/"CW-lat". And they SHOULD be tied together with their shared "BelongToK"
Link to .csv of Data: https://drive.google.com/open?id=1JsyEVqknEfcuakSXydFAq2OQ1eHYznSX