Cluster results on map

Hello
I carried out cluster analyzes on stations and species, and now I would like to represent my stations on a map in order to visualize the distribution of the different clusters.

I manage to do everything I want except assigning colors to clusters.
The "ZooK.asin.sqrt....K..6" column is the column that associates the cluster number with my stations.
The only color I manage to get with this code is a blue gradient so very inefficient to distinguish well
I tried with scale_fill_manual but it doesn't work...

How to do it ?

ggplot(data = world) +
  geom_sf(fill= "antiquewhite") +
  geom_point(data = df , aes(x = Longitude  , y = Latitude), size = 3, shape = 21) +
  geom_text_repel(data = df, aes(x = Longitude, y = Latitude, label = Station, colour = ZooK.asin.sqrt....K..6), 
                  fontface = "bold", nudge_x = c(1, -1.5, 2, 2, -1), nudge_y = c(0.25,-0.25, 0.5, 0.5, -0.5)) + 
  coord_sf(xlim = c(-145, -40), ylim = c(54, 85), expand = FALSE) +
  theme(panel.grid.major = element_line(color = gray(.5), linetype = "dashed", size = 0.5), panel.background = element_rect(fill = "aliceblue"))

Created on 2022-05-27 by the reprex package (v2.0.1)
Thanks very much

I would make a new column that is the character version of "ZooK.asin.sqrt....K..6". ggplot will then detect the discrete nature of the values and use discrete colors instead of a color gradient.
If you data frame is named DF,

DF$Cluster <- as.character(DF$ZooK.asin.sqrt....K..6)

Thanks very much ! It was what I wanted

Hello !
I take the liberty of calling on you again to know how to delete the rows of this new column created containing NA.

I would like to remove the missing stations but not for all the df, just for the new column cluster created

Thanks

I t is not possible to remove a row from just one column. Every column in a data frame must have the same number of rows. It is surprising that any row would have an NA value. Isn't every observation assigned to a cluster?
Can you explain more about why you want to remove the rows with NA?

Thanks for your response !

Indeed you do not have all the elements, sorry about that.

So, I have multiple columns with cluster numbers depending on if I have K=6 (our example) or K=10, etc.
But my columns also differ with respect to zooplankton or fish. And my problem is for my fish columns because they are not present at all stations so there is no data in some rows.
My columns with ZooK, all the lines are filled because the zooK is present in all the stations, on the other hand for the fish some stations are NA because no fish.

And I want to remove the rows with NA because after I want to plot my stations on a map and I don't want to have the stations where there is no fish
But I don't want to remove these rows from the original df because I'll need its to plot my zooK map..

Sorry for the confusion

I can't be much help with this. I have done very little plotting of maps. I could start guessing from my general knowledge of plotting in R but that might be a waste of your time. I suggest you start a new thread for this question. People are more likely to look at new thread as opposed to threads that are already marked as solved.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.