Put the name of the area on the site

I am trying to plot a map of the intensity of the regions of Ukraine, and the intensity depends on the "value". Here is my code:

library(sp)
con <- url("http://biogeo.ucdavis.edu/data/gadm2/R/UKR_adm1.RData")
print(load(con))
close(con)
name<-VARNAME_1
gadm$VARNAME_1
value<-c(1:27)
gadm$VARNAME_1<-as.factor(value)
col<- colorRampPalette(c('white', 'black'))(256) 
spplot(gadm, "VARNAME_1", main="Ukraine", scales = list(draw = TRUE), col.regions=col)

My question is: is it possible to overlay the names of regions on the plot (I have it as a vector of characters namein my code in the corresponding place on the map. Or, maybe, another suggestion to make the map more understandable and understandable, which area has the corresponding value. Thank you!

+4
source share
2 answers

One possibility is to do this with flowers:

colors=rainbow(length(gadm$NAME_1))
plot(gadm,col=colors)
legend("topleft",legend=gadm$NAME_1,fill=colors,cex=1.3,bty="n" )

enter image description here

or you add names with text:

colors=rainbow(length(gadm$NAME_1))
plot(gadm,col=colors)
text(coordinates(gadm), labels = gadm$NAME_1)

enter image description here

+2
source

plot spplot, text. spplot,

x11()
col = cm.colors(length(gadm$PID))
plot(gadm, , col=col[rev(gadm$VARNAME_1)])
text(coordinates(gadm), labels = gadm$NAME_1, cex=0.4)

, spplot, . this

sp.label <- function(x, label) {
    list("sp.text", coordinates(x), label)
}

NAME.sp.label <- function(x) {
    sp.label(x, x$NAME_1)
}

draw.sp.label <- function(x) {
    do.call("list", NAME.sp.label(x))
}

spplot(gadm, 'VARNAME_1', sp.layout = draw.sp.label(gadm))
+3

All Articles