0

Hallo everyone can anybody help me to upgrade my code with possibility of insering additional data into my map. This is the code that draw me a map with intensity of migration, and I am trying to add ehtnic information of every region (many small pie charts).

to draw a map

con <- url("http://biogeo.ucdavis.edu/data/gadm2/R/UKR_adm1.RData")
print(load(con))
close(con)
name<-gadm$VARNAME_1
value<-c(4,2,5,2,1,2,4,2,2,4,1,1,1,4,3,3,1,1,3,1,2,4,5,3,4,2,1)
gadm$VARNAME_1<-as.factor(value)
col<- colorRampPalette(c('cadetblue4','cadetblue1','mediumseagreen','tan2','tomato3'))(260) 
spplot(gadm, "VARNAME_1", main="Ukraine", scales = list(draw = TRUE), col.regions=col)

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), col.regions=col,
       colorkey = list(labels = list( labels = c("Very low","Low", "Average",
                                                 "High","Very high"),        
                                      width = 1, cex = 1)))

and this is a part of df, that I am trying to add to that map as pie charts or bar charts, with every latitude (lat) and longitude (long) to locate mu bar or pie charts.

df<-data.frame(region=c('Kiev oblast', 'Donezk oblast'), 
               rus=c(45,35), ukr=c(65,76), mold=c(11,44),long=c(50.43,48),
               lat=c(30.52, 37.82))

i found one example and another but... can't figure out how to use it in ma case. Hope for your help, thank you.

only that solution i have discovered by now, but it doesn't upgrade my code(((

mapPies( df,nameX="lat", nameY="long", nameZs=c('rus','ukr','mold'),
xlim=c(30,33), ylim=c(44,53), symbolSize = 2)
Community
  • 1
  • 1
Dima Sukhorukov
  • 129
  • 4
  • 13

1 Answers1

0

perhaps this will help:

pieSP The function provide SpatialPolygonsDataFrame depending on few attributes, ready to use for plotGoogleMaps or spplot.

library(plotGoogleMaps)

data(meuse)
coordinates(meuse)<-~x+y
proj4string(meuse) <- CRS('+init=epsg:28992')

pies <- pieSP(meuse,zcol=c('zinc','lead','copper'), max.radius=120)
pies$pie  <- rep(c('zinc','lead','copper'),155)
pies$pie2 <- rep(1:3,155)

spplot(pies, 'pie2')
ckluss
  • 1,477
  • 4
  • 21
  • 33