I have created a map in R.
However, I need the labels to sit just outside of the polygons so that the inside includes only the data points. Another alternative would be to color code each polygon and have a legend titled Statistical Areas (and the colors for 909, 910,911 corresponding). I would also like the y-axis to read as Latitude and the x-axis to read as Longitude. Below is the script I have used for the formatting. Does anyone know what I need to add to the script to make these alterations? Any help will be greatly appreciated!
ggplot(data = stats_shapefile) + geom_sf(fill= 'White')+
geom_sf(data=samples_sf)+ scale_fill_discrete("Statistical Area")+ geom_sf_text(aes(label = Statistica),size = 8 / .pt, position = "identity")

I had the exact same struggles you are having when trying to get my head around
ggplot2, and how to useaes()in particular. If you want to have something in a particular place for instance, you have to declare it insideaes(). The errors you are getting are becauseggplot()andgeom_text_repel()haven't been given the minimumaes()information they need.With that in mind, here's a repex to help you on your way. This involves creating intermediary data - sf_points - so that you can 'feed'
ggrepeltheaes()information it needs. There are other ways of doing this but I believe this approach is good readability-wise. NOTE: the example cra3 data are at the end of this answer.Note that the x, y, and label values for the CRA3 polygons were declared in
aes()so nowggrepel()knows what to write and where to put them:As before, to colour the polygons, you need to declare
fill =insideaes(). Then, usescale_fill_manual()to assign the colour values. R colour names and hex colour values e.g. #CC79A7 are accepted. This example uses hex values.The result:
Data: