0

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)

Result of #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")

Result for #2#

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" Snipp of data-frame

Link to .csv of Data: https://drive.google.com/open?id=1JsyEVqknEfcuakSXydFAq2OQ1eHYznSX

O_M_J
  • 9
  • 2
  • 1
    Folks might be able to help if you include a [reproducible sample of data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) in a format we can work with, i.e. not a picture of data – camille Apr 04 '19 at 01:44
  • Added the .csv file for the Data now: https://drive.google.com/open?id=1JsyEVqknEfcuakSXydFAq2OQ1eHYznSX – O_M_J Apr 05 '19 at 07:48
  • The link to making good R posts includes ways to provide data that *aren't* links for us to download—a lot of people won't want to randomly download files from a third party without a reason to trust what it is – camille Apr 05 '19 at 12:59

0 Answers0