[GIS] How to add labels to shapefile point layer in R

plotrshapefile

I have plotted a shapefile containing points in R, and I would like to add labels like : point 1, point 2 and so on..) to the plot.

Is this possible?

Best Answer

You can try a simple reproducible example below:

# Libraries for GIS
library('sp')

# Library for plot
library('latticeExtra')

# Load data ---------------------------------------------------------------

# Points
x <- c(1199999, 1080000, 1093067, 1090190, 1087977, 1070419, 1180419)
y <- c(957803,937803, 894366, 872153, 853703, 825353, 805353)

# Create SpatialPoints
SP <- SpatialPoints(coords = cbind(x,y))

# Add label variable
SP$ID <- paste("point", 1:7, sep = "")

# Plot
plot <- spplot(SP, zcol = "ID")
labels <- layer(sp.text(coordinates(SP), txt = SP$ID, pos = 1))

# plot + label layer
plot + labels

example

Related Question