I am trying to add district labels for a country, which I am plotting using levelplot (to use worldclim precipitation data) and adding boundaries using spplot.
I am having trouble adding text labels of the districts onto the map. I have the following code:
tan <- getData("GADM", country="Tanzania", level=1)
alt_world <-getData('worldclim', var='alt', res=10)
tanalt.sub <- crop(alt_world, extent(tan))
tan.sub <- mask(tanalt.sub, tan)
p1 <- levelplot(tan.sub, col.regions=colorRampPalette(brewer.pal(9, 'Blues')),margin=FALSE,main ='Tanzania rainfall (mm/year)')
p2 <- spplot(tan)
p <- p1+p2
I have tried the following to add labels:
labels <- layer(sp.text(coordinates(tan), txt = tan$NAME_1, pos = 1))
p2 <- p2 + labels
But get an error regarding 'inherited function for coordinates'.
Best Answer
Managed to solve it using ggplot2, however still looking at how to use labels with levelplot.
Edit, found a solution: