0

I am trying to add labels at each point, particularly the row names. I am using the following code:

Clust <- factor(as.factor(XYClass_df_4326$Class))
sa_map7_plt <- OpenStreetMap::autoplot.OpenStreetMap(sa_map2)                           +                                 
  geom_point( data = XYClass_df_4326, aes(x = X, y = Y,color = Clust ), size =  2.5  )  +
  geom_point( data = XYBord_df_4326,  aes(x = X, y = Y), size =  0.5   )                + 
#  geom_text(label=rownames(XYClass_df_4326))                                            +
  scale_colour_manual(breaks = c("1", "2", "3"),
                      values = c("red", "black", "blue"))                               +
  xlab("Longitude (°E)") + ylab("Latitude (°S)" ) 
sa_map7_plt

I have commented the geom_text function, because when I use it I get the following error: Error: Aesthetics must be either length 1 or the same as the data (1): label

When I comment this function, I get the following graph:

enter image description here

  • 3
    Without [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) one can only guess. But you could try with `geom_text( data = XYClass_df_4326, aes(x = X, y = Y, label=rownames(XYClass_df_4326)))` – stefan Apr 20 '22 at 17:52

0 Answers0