Georgia Mapping in R

You can download session 9 files for constructing the population pyramids of Georgia here: https://github.com/rladies/meetup-presentations_tbilisi and specify your working directory with setwd(“/Users/mydomain/myfolder/”)

#set working directory
mypath<-"/Users/DrSpengler/The rectification of the Vuldrini/"
#upload shape files
georgia <- readOGR("./GEO_adm/","GEO_adm0")
## OGR data source with driver: ESRI Shapefile
## Source: "./GEO_adm/", layer: "GEO_adm0"
## with 1 features
## It has 70 fields
# plot(georgia, lwd=1.5)

georgia1 <- readOGR("./GEO_adm/","GEO_adm1")
## OGR data source with driver: ESRI Shapefile
## Source: "./GEO_adm/", layer: "GEO_adm1"
## with 12 features
## It has 16 fields
# plot(georgia1)

georgia2 <- readOGR("./GEO_adm/","GEO_adm2")
## OGR data source with driver: ESRI Shapefile
## Source: "./GEO_adm/", layer: "GEO_adm2"
## with 69 features
## It has 18 fields
# plot(georgia2)

gwat <- readOGR("./GEO_wat/" , "GEO_water_lines_dcw")
## OGR data source with driver: ESRI Shapefile
## Source: "./GEO_wat/", layer: "GEO_water_lines_dcw"
## with 559 features
## It has 5 fields
# plot(gwat)

gpop <- raster("./GEO_pop/geo_pop.grd")
# plot(gpop)

galt <- raster("./GEO_msk_alt/GEO_msk_alt.grd")
# plot(galt)
 plot(georgia, lwd=1.5) #n1

map1

 plot(georgia1, lwd=1.5) #n2

map2

 plot(georgia2, lwd=1.5) #n3

map3

 plot(georgia, lwd=1.5) #n4
 plot(gwat, lwd=1.5, col="blue", add=T) #n4

map4

 plot(gpop) #n5
 plot(georgia, lwd=1.5,  add=T) #n5

map5

 plot(galt, lwd=1.5) #n6

map6

Plot neighbouring countries

tur <- readOGR("./TUR_adm" , "TUR_adm0")
## OGR data source with driver: ESRI Shapefile
## Source: "./TUR_adm", layer: "TUR_adm0"
## with 1 features
## It has 70 fields
## Integer64 fields read as strings:  ID_0 OBJECTID_1
arm <- readOGR("./ARM_adm" , "ARM_adm0")
## OGR data source with driver: ESRI Shapefile
## Source: "./ARM_adm", layer: "ARM_adm0"
## with 1 features
## It has 70 fields
## Integer64 fields read as strings:  ID_0 OBJECTID_1
rus <- readOGR("./RUS_adm" , "RUS_adm0")
## OGR data source with driver: ESRI Shapefile
## Source: "./RUS_adm", layer: "RUS_adm0"
## with 1 features
## It has 70 fields
## Integer64 fields read as strings:  ID_0 OBJECTID_1
aze <- readOGR("./AZE_adm" , "AZE_adm0")
## OGR data source with driver: ESRI Shapefile
## Source: "./AZE_adm", layer: "AZE_adm0"
## with 1 features
## It has 70 fields
## Integer64 fields read as strings:  ID_0 OBJECTID_1

plot maps

plot(georgia, lwd=1.5, col="white", bg="lightblue")
plot(georgia1, add=T, lty=2)
plot(tur, add=T, col="white")
plot(arm, add=T, col="white")
plot(rus, add=T, col="white")
plot(aze, add=T, col="white")

map7

add labels for the countries

x.loc <- c(44.32002, 46.35746, 44.40421, 42.18156, 40.71662)
y.loc <- c(43.42472, 40.87209, 40.82228, 40.90945, 41.99276)
nb.lab <- c("Russia", "Azerbaijan", "Armenia", "Turkey", "Black Sea")
plot(georgia, lwd=1.5, col="white", bg="lightblue")
plot(georgia1, add=T, lty=2)
plot(tur, add=T, col="white")
plot(arm, add=T, col="white")
plot(rus, add=T, col="white")
plot(aze, add=T, col="white")
text(x.loc, y.loc, nb.lab)

let’s add everything (or almost everything) together

plot(gwat, col="blue")
# plot(georgia1[1,], lwd=1, col="lightblue", border="black", add=T)
plot(georgia2, lwd=0.5, border="black", lty=3, add=T)
plot(georgia1, border="black", lty=2, add=T)
plot(georgia, lwd=1.5, add=T)

map8

check georgia@data

head(georgia1)
##   ID_0 ISO  NAME_0 ID_1       NAME_1 VARNAME_1 NL_NAME_1 HASC_1 CC_1
## 0   81 GEO Georgia 1034     Abkhazia   Sokhumi      <NA>  GE.AB <NA>
## 1   81 GEO Georgia 1035       Ajaria    Batumi      <NA>  GE.AJ <NA>
## 2   81 GEO Georgia 1036        Guria  Ozurgeti      <NA>  GE.GU <NA>
## 3   81 GEO Georgia 1037      Imereti   Kutaisi      <NA>  GE.IM <NA>
## 4   81 GEO Georgia 1038      Kakheti    Telavi      <NA>  GE.KA <NA>
## 5   81 GEO Georgia 1039 Kvemo Kartli   Rustavi      <NA>  GE.KK <NA>
##                   TYPE_1           ENGTYPE_1 VALIDFR_1 VALIDTO_1 REMARKS_1
## 0 Avtonomiuri Respublika Autonomous Republic      1994   Present      <NA>
## 1 Avtonomiuri Respublika Autonomous Republic      1994   Present      <NA>
## 2                 Region              Region      1994   Present      <NA>
## 3                 Region              Region      1994   Present      <NA>
## 4                 Region              Region      1994   Present      <NA>
## 5                 Region              Region      1994   Present      <NA>
##   Shape_Leng Shape_Area
## 0   6.643211  0.9744622
## 1   3.055014  0.3074264
## 2   2.880653  0.2092665
## 3   4.214567  0.6783179
## 4   6.820519  1.2485036
## 5   5.219352  0.6807876

print labels on the map

labels for admin 2

coords2<- coordinates(georgia2[2:6,])
admin2 <- c(as.character(georgia2$NAME_2[1:5]))
admin2
## [1] "Gagra"      "Gali"       "Gudauta"    "Gulripshi"  "Ochamchire"

Upload data from World Bank

dt <- read.csv("/Users/ac1y15/Google Drive/blog/RLadies_Georgia_files/Session_3/Data_Extract_From_Subnational_Malnutrition/3f075abc-c51c-40c5-afb1-f8fbcfa30f23_Data.csv", header=T)
dt.1 <- subset(dt, dt$type==1&dt$select==1)

head(dt.1)
##            Admin.Region.Name select order
## 6                                 1     1
## 7  Georgia, Adjara Aut. Rep.      1     2
## 16            Georgia, Guria      1     3
## 26          Georgia, Imereti      1     4
## 31          Georgia, Kakheti      1     5
## 36     Georgia, Kvemo Kartli      1     6
##                         Admin.Region.Code type
## 6                                            1
## 7  GEO_Adjara_Aut._Rep._GE.AR_1297_GEO002    1
## 16            GEO_Guria_GE.GU_1298_GEO003    1
## 26          GEO_Imereti_GE.IM_1299_GEO004    1
## 31          GEO_Kakheti_GE.KA_1300_GEO005    1
## 36     GEO_Kvemo_Kartli_GE.KK_1301_GEO006    1
##                                                            Series.Name
## 6
## 7  Prevalence of overweight, weight for height (% of children under 5)
## 16 Prevalence of overweight, weight for height (% of children under 5)
## 26 Prevalence of overweight, weight for height (% of children under 5)
## 31 Prevalence of overweight, weight for height (% of children under 5)
## 36 Prevalence of overweight, weight for height (% of children under 5)
##          Series.Code YR2000 YR2005 YR2009
## 6                        NA     NA     NA
## 7  SN.SH.STA.OWGH.ZS     NA   28.1     NA
## 16 SN.SH.STA.OWGH.ZS     NA    7.9     NA
## 26 SN.SH.STA.OWGH.ZS    9.9   21.5     NA
## 31 SN.SH.STA.OWGH.ZS    7.0   19.6   13.2
## 36 SN.SH.STA.OWGH.ZS    9.5   28.2   19.1

Map the prevalence overweight w/h

library(classInt)
nclassint <- 3 #number of colors to be used in the palette
cat <- classIntervals(dt.1$YR2005, nclassint,style = "quantile") #style refers to how the breaks are created
colpal <- brewer.pal(nclassint,"Greens") #sequential
color.palette <- findColours(cat,colpal)
is.na(color.palette)
##  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
## [12] FALSE
bins <- cat$brks
lb <- length(bins)

color.palette[c(1, 10)] <- "gray"
value.vec <- c(round(bins[-length(bins)],2))
value.vec.tail <- c(round(bins[-1],2))

Plot and SAVE map:

plot(georgia1, col=color.palette, border=T, main="Prevalence of overweight, \nweight for height (% of children under 5)")
legend("topright",fill=c("gray", "#E5F5E0", "#A1D99B", "#31A354"),legend=c("NA",paste(value.vec,":",value.vec.tail)),cex=1.1, bg="white", bty = "n")
# map.scale(41, 41, 2, "km", 2, 100)
map.scale(x=40.1, y=41.2, relwidth=0.1 , metric=T, ratio=F, cex=0.8)
SpatialPolygonsRescale(layout.north.arrow(2), offset= c(40.1, 41.6), scale = 0.5, plot.grid=F)

map12

See you at IUSSP to talk about the fantastic work we do at WorldPop! (plus Demotrends and R-Ladies)

As IUSSP is approaching, I’m looking forward to talk more about fine grid scale mapping research at WorldPop (University of Southampton) and Flowminder.

I will present my research on  the 30th of October in session 5 at 8:30am Integrating spatial and statistical methods in demographic research, meeting room 1.41 and 1.42.

Prof. Andy Tatem will host a side meeting Geospatial Demography: Combining Satellite, Survey, Census and Cellphone Data to Provide Small-area Estimates on the 29 October 2017, 8:30-16:00.

and  will be contributing to the Cape Town R-Ladies chapter Saturday 4 November (details here) with a talk on R-Ladies and data visualization in ggplot2. Come talk to us and become an R-Lady, we are looking forward to sharing our experiences.

A few Demotrend(ers) will also be presenting at IUSSP, come talk to us 🙂

See you in Cape Town!

 

Long to wide format with tidyr (and save it in n files)

The data comes from the https://esa.un.org/unpd/wpp/UN population projections

library(tidyr) #load tidyr or <a href="https://www.tidyverse.org/">tidyverse</a>, the latter being a collection of libraries

setwd("/Users/...") #set your working directory

dt <- read.csv("mydataset.csv", header=T) #read data

head(dt) #look at data

##   Index       Country Year Age Male_Pop Female_Pop
## 1     1 AmericanSamoa 2000   0      874        836
## 2     2 AmericanSamoa 2000   1      773        747
## 3     3 AmericanSamoa 2000   2      760        735
## 4     4 AmericanSamoa 2000   3      783        760
## 5     5 AmericanSamoa 2000   4      820        796
## 6     6 AmericanSamoa 2000   5      851        825

The idea would be to have a KEY column with the variables names and a VALUE column with the values. Since we have 2 value columns (male_pop and female_pop) we first need to gather them into 1 value column (Pop_sex) and then paste Pop_sex with Age.

# get it into the right format for "spread"
dt1 <- dt %>%

  gather(Pop_sex, value, 5:6) %>%

  unite(Pop_age, 5, 4, sep="_", remove=T) %>% # paste cols 5 and 4

  spread(Pop_age, value) %>% # spread into wide format

  write.csv(., file = "~/My folder of choice/nameofmyfile.csv") # this is optional

There’s a useful trick I’ve been using to get n csv files out of one long format dataset (eg. 1 file per year), I’ve found this somewhere in stackoverflow:

customFun  = function(mydt) {
  write.csv(mydt,paste0("name_",unique(mydt$year),".csv"))
  return(mydt)
}

mydt %>% 
  unite(newvar, 3:4, sep="_", remove=T) %>%
  spread(newvar, value) %>%
  group_by(year) %>% 
  do(customFun(.))

Note of the author: wide formats are never very useful but in case you really need them (linear regression &co) tidyr is a very compact solution. Be mindful that spreading over >1000 cols takes time. To get back from wide to long format use gather

Geofacet: Bangladesh 64 districts education

Geofacet example using World Bank data on Bangladesh education attainment

  1. set up grids
  2. upload data, source: World Bank
  3. plot and save

1. Grid for Bangladesh districts:

library(tidyverse)
library(geofacet)
library(ggthemes)
options(scipen = 99)
mygrid <- data.frame(
row = c(1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11),
col = c(3, 2, 3, 4, 3, 4, 5, 3, 4, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 9),
code = c("BG01","BG02","BG03","BG04","BG05","BG06","BG07","BG08","BG09","BG10","BG11","BG12","BG13","BG14","BG15","BG16","BG17","BG18","BG19","BG20","BG21","BG22","BG23","BG24","BG25","BG26","BG27","BG28","BG29","BG30","BG31","BG32","BG33","BG34","BG35","BG36","BG37","BG38","BG39","BG40","BG41","BG42","BG43","BG44","BG45","BG46","BG47","BG48","BG49","BG50","BG51","BG52","BG53","BG54","BG55","BG56","BG57","BG58","BG59","BG60","BG61","BG62","BG63", "BG64"),
name = c("Panchagar","Takurgaong","Nilphamar","Lamonirhat","Dinajpur","Rangpur","Kurigram","Jaipurat","Gaibandha","Naogaon","Bogra","Jamalpur","Sherpar","Mymensingh","Netrokona","Suramganj","Sylhet","Chapai","Rajshani","Nator","Sirajganj","Tangail","Gazipur","Kishoreganj","Habiganj","Moulvibazar","Kushtia","Pabna","Dhaka","Nardiaganj","Narsingdi","Brahmanbaria","Meherpur","Jhenaidah","Magura","Rajbari","Manikganj","Munshiganj","Comilla","Khagrachhari","Rangramati","Chuadanga","Jessore","Gopalganj","Faridpur","Madanipur","Shariyapur","Chandpur","Feni","Chittagong","Badanbari","Narail","Pirojpur","Barisal","Jhalkati","Laksimipur","Noakhali","Satkhira","Khulna","Bagerhat","Borguna","Patuakhali","Bhola","Cox's Bazar"),
stringsAsFactors = FALSE
)

Preview the grid:

geofacet::grid_preview(mygrid)

Screen Shot 2017-07-23 at 16.17.02.png

2. Data from World Bank

dt3<-structure(list(ordinal = c(58L, 58L, 58L, 58L, 58L, 58L, 58L, 34L, 56L, 57L, 34L, 56L, 57L, 34L, 56L, 57L, 34L, 56L, 57L, 34L, 56L, 57L, 34L, 56L, 57L, 34L, 56L, 57L, 53L, 55L, 59L, 53L, 55L, 59L, 53L, 55L, 59L, 53L, 55L, 59L, 53L, 55L, 59L, 53L, 55L, 59L, 53L, 55L, 59L, 47L, 54L, 47L, 54L, 47L, 54L, 47L, 54L, 47L, 54L, 47L, 54L, 47L, 54L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 22L, 27L, 30L, 33L, 45L, 48L, 63L, 64L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 20L, 23L, 46L, 49L, 51L, 52L, 60L, 61L, 62L, 8L, 18L, 28L, 29L, 40L, 50L, 8L, 18L, 28L, 29L, 40L, 50L, 8L, 18L, 28L, 29L, 40, 50L, 8L, 18L, 28L, 29L, 40L, 50L, 8L, 18L, 28L, 29L, 40L, 50L, 8L, 18L, 28L, 29L, 40L, 50L, 8L, 18L, 28L, 29L, 40L, 50L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 11L, 25L, 26L, 31L, 38L, 41L, 42L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 9L, 13L, 14L, 17L, 19L, 21L, 24L, 32L, 36L, 37L, 2L, 4L,6L, 7L, 10L, 15L, 16L, 43L, 2L, 4L, 6L, 7L, 10L, 15L, 16L, 43L, 2L, 4L, 6L, 7L, 10L, 15L, 16L, 43L, 2L, 4L, 6L, 7L, 10L, 15L, 16L, 43L, 2L, 4L, 6L, 7L, 10L, 15L, 16L, 43L, 2L, 4L, 6L, 7L, 10L, 15L, 16L, 43L, 2L, 4L, 6L, 7L, 10L, 15L, 16L, 43L, 1L, 3L, 5L, 12L, 35L, 39L, 44L, 1L, 3L, 5L, 12L, 35L, 39L, 44L, 1L, 3L,
5L, 12L, 35L, 39L, 44L, 1L, 3L, 5L, 12L, 35L, 39L, 44L, 1L, 3L, 5L, 12L, 35L, 39L, 44L, 1L, 3L, 5L, 12L, 35L, 39L, 44L, 1L, 3L, 5L, 12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, 30L, 56L, 15L, 30L, 56L, 15L, 30L, 56L, 15L, 30L, 56L, 26L, 18L, 26L, 18L, 26L, 18L,
26L, 18L, 26L, 18L, 26L, 18L, 26L, 18L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 22L, 40L, 46L, 59L, 6L, 41L, 61L, 62L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 19L, 29L, 9L, 45L, 54L, 60L, 64L, 21L, 37L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 12L, 36L, 39L, 53L, 25L, 35L, 38L, 12L, 36L, 39L, 53L, 25L, 35L, 38L, 12L, 36L, 39L, 53L, 25L, 35L, 38L, 12L, 36L, 39L, 53L, 25L, 35L, 38L, 12L, 36L, 39L, 53L, 25L, 35L, 38L, 12L, 36L, 39L, 53L,
25L, 35L, 38L, 12L, 36L, 39L, 53L, 25L, 35L, 38L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 8L, 17L, 27L, 55L, 16L, 20L, 34L, 58L, 11L, 23L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 4L, 24L, 52L, 2L, 10L, 32L, 48L, 42L, 3L, 5L, 51L, 13L, 1L, 28L, 57L, 3L, 5L, 51L, 13L, 1L, 28L, 57L, 3L, 5L, 51L, 13L, 1L, 28L, 57L, 3L, 5L, 51L, 13L, 1L, 28L, 57L, 3L, 5L, 51L, 13L, 1L, 28L, 57L, 3L, 5L, 51L, 13L, 1L, 28L, 57L, 3L, 5L, 51L, 13L, 1L, 28L, 57L), .Label = c("BAGERHAT", "BANDARBAN", "BARGUNA", "BARISAL",
"BHOLA", "BOGRA", "BRAHMANBARIA", "CHANDPUR", "CHAPAI NABABGANJ", "CHITTAGONG", "CHUADANGA", "COMILLA", "COX'S BAZAR", "DHAKA", "DINAJPUR", "FARIDPUR", "FENI", "GAIBANDHA", "GAZIPUR", "GOPALGANJ", "HABIGANJ", "JAMALPUR", "JESSORE", "JHALOKATI", "JHENAIDAH", "JOYPURHAT", "KHAGRACHHARI", "KHULNA", "KISHOREGANJ", "KURIGRAM", "KUSHTIA", "LAKSHMIPUR", "LALMONIRHAT", "MADARIPUR", "MAGURA",
"MANIKGANJ", "MAULVIBAZAR", "MEHERPUR", "MUNSHIGANJ", "MYMENSINGH", "NAOGAON", "NARAIL", "NARAYANGANJ", "NARSINGDI", "NATORE", "NETRAKONA", "NILPHAMARI", "NOAKHALI", "PABNA", "PANCHAGARH", "PATUAKHALI", "PIROJPUR", "RAJBARI", "RAJSHAHI", "RANGAMATI", "RANGPUR", "SATKHIRA", "SHARIATPUR", "SHERPUR", "SIRAJGANJ", "SUNAMGANJ", "SYLHET", "TANGAIL", "THAKURGAON"), class = "factor"), name = structure(c(50L, 50L, 50L, 50L, 50L, 50L, 50L, 64L, 33L, 47L, 64L, 33L, 47L, 64L, 33L, 47L, 64L, 33L, 47L, 64L, 33L, 47L, 64L, 33L, 47L, 64L, 33L,
47L, 15L, 30L, 55L, 15L, 30L, 55L, 15L, 30L, 55L, 15L, 30L, 55L, 15L, 30L, 55L, 15L, 30L, 55L, 15L, 30L, 55L, 22L, 18L, 22L, 18L, 22L, 18L, 22L, 18L, 22L, 18L, 22L, 18L, 22L, 18L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 23L, 40L, 46L, 59L, 5L, 41L, 61L, 62L, 19L, 29L, 9L, 45L, 54L, 60L, 63L, 21L, 38L, 19L, 29L, 9L, 45L, 54L, 60L, 63L, 21L, 38L, 19L, 29L, 9L, 45L, 54L, 60L, 63L, 21L, 38L, 19L, 29L, 9L, 45L, 54L, 60L, 63L, 21L, 38L, 19L, 29L, 9L, 45L, 54L, 60L, 63L, 21L, 38L, 19L, 29L, 9L, 45L, 54L, 60L,
63L, 21L, 38L, 19L, 29L, 9L, 45L, 54L, 60L, 63L, 21L, 38L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 7L, 14L, 43L, 44L, 31L, 49L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 12L, 36L, 39L, 53L, 26L, 35L, 37L, 8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L, 8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L, 8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L, 8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L,
8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L, 8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L, 8L, 17L, 27L, 56L, 16L, 20L, 34L, 58L, 11L, 24L, 3L, 25L, 52L, 1L, 10L, 32L, 48L, 42L, 3L, 25L, 52L, 1L, 10L, 32L, 48L, 42L, 3L, 25L, 52L, 1L, 10L, 32L, 48L, 42L, 3L, 25L, 52L, 1L, 10L, 32L, 48L, 42L, 3L, 25L, 52L,
1L, 10L, 32L, 48L, 42L, 3L, 25L, 52L, 1L, 10L, 32L, 48L, 42L, 3L, 25L, 52L, 1L, 10L, 32L, 48L, 42L, 6L, 4L, 51L, 13L, 2L, 28L, 57L, 6L, 4L, 51L, 13L, 2L, 28L, 57L, 6L, 4L, 51L, 13L, 2L, 28L, 57L, 6L, 4L, 51L, 13L, 2L, 28L, 57L, 6L, 4L, 51L, 13L, 2L, 28L, 57L, 6L, 4L, 51L, 13L, 2L, 28L, 57L, 6L, 4L, 51L, 13L, 2L, 28L, 57L), .Label = c("Badanbari", "Bagerhat", "Barisal", "Bhola", "Bogra", "Borguna", "Brahmanbaria", "Chandpur", "Chapai", "Chittagong", "Chuadanga", "Comilla", "Cox's Bazar", "Dhaka", "Dinajpur", "Faridpur", "Feni", "Gaibandha", "Gazipur", "Gopalganj", "Habiganj", "Jaipurat", "Jamalpur", "Jessore", "Jhalkati", "Jhenaidah", "Khagrachhari", "Khulna", "Kishoreganj", "Kurigram", "Kushtia", "Laksimipur", "Lamonirhat", "Madanipur", "Magura", "Manikganj", "Meherpur", "Moulvibazar", "Munshiganj", "Mymensingh", "Naogaon", "Narail",
"Nardiaganj", "Narsingdi", "Nator", "Netrokona", "Nilphamar", "Noakhali", "Pabna", "Panchagar", "Patuakhali", "Pirojpur", "Rajbari", "Rajshani", "Rangpur", "Rangramati", "Satkhira", "Shariyapur", "Sherpar", "Sirajganj", "Suramganj", "Sylhet", "Takurgaong", "Tangail"), class = "factor"), row = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6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1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 4L, 6L, 5L, 4L, 6L, 5L, 4L, 6L, 5L, 4L, 6L, 5L, 4L, 6L, 5L, 4L, 6L, 5L, 4L, 6L, 5L, 7L, 13L, 7L, 13L, 7L, 13L, 7L, 13L, 7L, 13L, 7L, 13L, 7L, 13L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 10L, 15L, 16L, 14L, 9L, 8L, 11L, 17L, 23L, 24L, 18L, 20L, 19L, 21L,22L,25L,26L,23L,24L,18L,20L,19L,21L,22L,25L,26L,23L,24L,
18L,20L,19L,21L,22L,25L,26L,23L,24L,18L,20L,19L,21L, 22L,25L,26L,23L, 24L, 18L, 20L, 19L, 21L, 22L, 25L, 26L, 23L, 24L, 18L, 20L, 19L, 21L, 22L, 25L, 26L, 23L, 24L, 18L, 20L, 19L, 21L, 22L, 25L, 26L, 32L, 29L, 30L, 31L, 27L, 28L, 32L, 29L, 30L, 31L, 27L, 28L, 32L, 29L, 30L, 31L, 27L, 28L, 32L, 29L, 30L, 31L, 27L, 28L, 32L, 29L, 30L, 31L, 27L, 28L, 32L, 29L, 30L, 31L, 27L, 28L, 32L, 29L, 30L, 31L, 27L, 28L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 39L, 37L, 38L, 36L, 34L, 35L, 33L, 48L, 49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 48L, 49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 48L, 49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 48L, 49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 48L, 49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 48L, 49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 48L,
49L, 40L, 41L, 45L, 44L, 46L, 47L, 42L, 43L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 54L, 55L, 53L, 51L, 50L, 56L, 57L, 52L, 61L, 63L, 62L, 64L, 60L, 59L, 58L, 61L, 63L, 62L, 64L, 60L, 59L, 58L, 61L, 63L, 62L, 64L, 60L, 59L, 58L, 61L, 63L, 62L, 64L, 60L, 59L, 58L, 61L, 63L, 62L, 64L, 60L, 59L, 58L, 61L, 63L, 62L, 64L, 60L, 59L, 58L, 61L, 63L, 62L, 64L, 60L, 59L, 58L), .Label = c(" BG02", " BG03", " BG04", " BG05", " BG06", " BG07", " BG08", " BG10", " BG11", " BG12", " BG16", "BG01", "BG09", "BG13", "BG14", "BG15", "BG17", "BG18", "BG19", "BG20", "BG21", "BG22", "BG23", "BG24", "BG25", "BG26", "BG27", "BG28", "BG29", "BG30", "BG31", "BG32", "BG33", "BG34", "BG35", "BG36", "BG37", "BG38", "BG39", "BG40", "BG41", "BG42", "BG43", "BG44", "BG45", "BG46", "BG47", "BG48", "BG49", "BG50", "BG51", "BG52", "BG53", "BG54", "BG55", "BG56", "BG57", "BG58", "BG59", "BG60", "BG61", "BG62", "BG63", "BG64"), class = "factor"),
type = structure(c(1L, 2L, 3L, 4L, 1L, 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 50.3, 50.3, 50.3, 12.8, 12.8,     12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 35.4, 62.1, 59.7, 54.4, 48.4, 60.9, 55, 61.6, 53.9, 43.3, 28.1, 29.2, 32, 33, 27.2, 30.4, 30.2, 35.6, 17.5, 8.1, 8.7, 10.7, 13.5, 9.7, 11.3, 6.9, 8.7, 3.8, 1.8, 2.3, 2.8, 5.1, 2.2, 3.2, 1.3, 1.8, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8,     12.8, 12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8,     3.8, 56.8, 28.8, 42.7, 51.7, 57, 56.7, 32.1, 34.8, 39.1,     34.6, 28.6, 29.1, 9.4, 23.3, 14.8, 11.3, 11.5, 11.3, 1.7,     13.1, 3.5, 2.4, 2.9, 2.8, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3,     12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 47.3, 56.1, 49, 56.7, 54.3, 53, 59.8, 36.1, 31.8, 38.4,     31, 33.1, 33.3, 29.9, 13.9, 10, 10.8, 10, 10.1, 11.2, 8.2,     2.7, 2.1, 1.8, 2.4, 2.5, 2.6, 2, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 44.7, 38.8, 59.3, 57, 54.5, 46.4, 56, 58.9, 55, 46.5, 40.1, 41.1, 29.5, 29, 32.8, 40, 32.6, 32.3, 34.3, 36.5, 12.9, 17, 9.3, 11.5, 10, 11, 9.2, 7.3, 8.9, 13.4, 2.3, 3.1, 1.9, 2.5, 2.6, 2.6, 2.1, 1.5, 1.8, 3.5, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8,  12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 39.8, 33.8, 36.6, 70, 38.9, 52.9, 47.6, 49.4, 41.2, 46, 45.9, 20.9, 36.3, 34.8, 38.2, 36.8, 15.2, 17.1, 14.4, 7.6, 19.1, 10.4, 12, 11.3, 3.8, 3.1, 3, 1.5, 5.8, 2, 2.2, 2.5, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 12.8,  12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 43.6, 60.6, 48.1, 62.3, 42.8, 41.1, 51.3, 42.9, 28.6, 37.8, 27.1, 41.4, 36.7, 35.1, 11.1, 8.8, 11.7, 8.6, 12.8, 16.8, 10.9, 2.3, 2.1, 2.4, 2, 3, 5.4, 2.7, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 50.3, 12.8, 12.8, 12.8,    12.8, 12.8, 12.8, 12.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8    )), .Names = c("ordinal", "Division.Name", "Zila.Name", "name", "row", "col", "code", "type", "mean", "value"), class = "data.frame", row.names = c(NA, -448L))

3. Plot and save:

library(ggplot2)
p <- ggplot(dt3 , aes(type, value, fill=type))+
geom_col(position = position_dodge())+
scale_fill_manual(values = c("#7fc97f", "#beaed4","#fdc086","#ffff99"))+
themebw()+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()),
plot.title=element_text(size=20, face="bold"))+
facet_geo(~name, grid = mygrid) +
labs(title = "Educational attainment in Bangladesh", fill="Edu attainment%",
caption = "By Aledemogr    Source: World Bank"
)
# ggsave("bgd1.png",height = 17, width = 10)</code>

 

bgd1

Geofacet: Nepal 75 districts

Screen Shot 2017-07-20 at 16.07.30row,col,code,name
1,4, NP01, Humla
1,5, NP02, Mugu
1,6, NP03, Dolpa
1,7, NP04, Mustang
1,8, NP05, Manang
2,9, NP06, Gorkha
2,1, NP07, Dharchula
2,2, NP08, Bajhang
2,3, NP09, Bajura
2,4, NP10, Kalikot
2,5, NP11, Jumla
2,6, NP12, Rukum
2,7, NP13, Myagdi
2,8, NP14, Kaski
2,10, NP15, Dhading
2,11, NP16, Rasuwa
2,12, NP17, Sindhupalchowk
2,13, NP18, Dolakha
2,14, NP19, Solukhumbu
2,15, NP20, Sankhuwasabha
2,16, NP21, Taplejung
3,9, NP22, Lamjung
3,1, NP23, Baitadi
3,2, NP24, Doti
3,3, NP25, Achham
3,4, NP26, Dailekh
3,5, NP27, Jajarkot
3,6, NP28, Rolpa
3,7, NP29, Baglung
3,8, NP30, Parbat
3,10, NP31, Nuwakot
3,11, NP32, Kavrepalanchok
3,12, NP33, Kathmandu
3,13, NP34, Okhaldhunga
3,14, NP35, Khotang
3,15, NP36, Bhojpur
3,16, NP37, Dhankuta
3,17, NP38, Tehrathum
4,9, NP39, Tanahun
4,1, NP40, Kanchanpur
4,2, NP41, Dadeldhura
4,3, NP42, Kailali
4,4, NP43, Surkhet
4,5, NP44, Salyan
4,6, NP45, Pyuthan
4,7, NP46, Gulmi
4,8, NP47, Syangja
4,10, NP48, Chitwan
4,11, NP49, Patan
4,12, NP50, Bhaktapur
4,13, NP51, Ramechhap
4,14, NP52, Udayapur
4,15, NP53, Sunsari
4,16, NP54, Panchthar
4,17, NP55, Ilam
5,9, NP56, Nawalparasi
5,4, NP57, Bardiya
5,5, NP58, Banke
5,6, NP59, Dang
5,7, NP60, Argakhanchi
5,8, NP61, Palpa
5,10, NP62, Parsa
5,11, NP63, Makwanpur
5,12, NP64, Sindhuli
5,13, NP65, Dhanussa
5,14, NP66, Siraha
5,15, NP67, Saptari
5,16, NP68, Morang
5,17, NP69, Jhapa
6,7, NP70, Kapilvastu
6,8, NP71, Rupandehi
6,10, NP72, Bara
6,11, NP73, Rahuttahat
6,12, NP74, Sarlahi
6,13, NP75, Mahottari

Geofacet grids: Nigeria Federal States

Geofacet grid for Nigeria’s 37 Federal States (below):

Screen Shot 2017-07-20 at 12.31.24.png

row,col,code,name
1,4,NG.KT,Katsina
1,5, NG.KN, Kano
1,2,NG.SO,Sokoto
1,3, NG.ZA, Zamfara
1,6, NG.JI, Jigawa
1,7, NG.YO, Yobe
2,2, NG.KE, Kebbi
2,3, NG.NI, Niger
2,4, NG.KD, Kaduna
2,7, NG.BO, Borno
2,6, NG.GO, Gombe
2,5, NG.BA, Bauchi
3,1, NG.OY, Oyo
3,2, NG.KW, Kwara
3,3,NG.FC, Abuja FCT
3,4, NG.NA, Nassarawa
3,6, NG.AD, Adamawa
3,5, NG.PL, Plateau
4,3, NG.EK, Ekiti
4,1, NG.OG, Ogun
4,2, NG.OS, Osun
4,4, NG.KO, Kogi
4,6, NG.TA, Taraba
4,5, NG.BE, Benue
5,3,NG.ED, Edo
5,1, NG.LA, Lagos
5,2, NG.ON, Ondo
5,6,NG.EB, Ebonyi
5,4, NG.AN, Anambra
5,5, NG.EN, Enugu
6,2, NG.DE, Delta
6,3, NG.IM, Imo
6,4,NG.AB, Abia
6,5, NG.CR, Cross River
7,3, NG.BY, Bayelsa
7,4, NG.RI, Rivers
7,5, NG.AK, Akwa Ibom

Plot maps with base mapping tools and ggmap in R

Plot maps with ‘base’ mapping tools in R

Understanding what kind of data you have (polygons or points?) and what you want to map is pivotal to start your mapping.

  1. First you need a shapefile of the area you want to plot, such as metropolitan France. There are various resources where to get them from: DIVA-GIS and EUROSTAT are those that I use the most. It’s always important to have a .prj file included, as your final map ‘should’ be projecte. I say “should” as sometimes it is just not possible, especially if you work with historical maps.
  2. Upload libraries

Load and prepare data

setwd(paste(mypath))
fr.prj <- readOGR(".", "FRA_adm2")
## OGR data source with driver: ESRI Shapefile
## Source: ".", layer: "FRA_adm2"
## with 96 features
## It has 18 fields
## NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
map(fr.prj)
rplot
## Warning in SpatialPolygons2map(database, namefield = namefield): database
## does not (uniquely) contain the field 'name'.

head(fr.prj@data)
##   ID_0 ISO NAME_0 ID_1    NAME_1  ID_2         NAME_2   VARNAME_2
## 0   76 FRA France  989    Alsace 13755       Bas-Rhin  Unterelsaá
## 1   76 FRA France  989    Alsace 13756      Haut-Rhin   Oberelsaá
## 2   76 FRA France  990 Aquitaine 13757       Dordogne        <NA>
## 3   76 FRA France  990 Aquitaine 13758        Gironde Bec-D'Ambes
## 4   76 FRA France  990 Aquitaine 13759         Landes      Landas
## 5   76 FRA France  990 Aquitaine 13760 Lot-Et-Garonne        <NA>
##   NL_NAME_2 HASC_2 CC_2      TYPE_2  ENGTYPE_2 VALIDFR_2 VALIDTO_2
## 0      <NA>  FR.BR <NA> Département Department  17900226   Unknown
## 1      <NA>  FR.HR <NA> Département Department  17900226   Unknown
## 2      <NA>  FR.DD <NA> Département Department  17900226   Unknown
## 3      <NA>  FR.GI <NA> Département Department  17900226   Unknown
## 4      <NA>  FR.LD <NA> Département Department  17900226   Unknown
## 5      <NA>  FR.LG <NA> Département Department  17900226   Unknown
##   REMARKS_2 Shape_Leng Shape_Area
## 0      <NA>   4.538735  0.5840273
## 1      <NA>   3.214178  0.4198797
## 2      <NA>   5.012795  1.0389622
## 3      <NA>   9.200047  1.1489822
## 4      <NA>   5.531231  1.0372815
## 5      <NA>   4.489830  0.6062017
# load or create data
set.seed(100)
myvar <- rnorm(1:96)
# manipulate data for the plot
france.geodata  <- data.frame(id=rownames(fr.prj@data), mapvariable=myvar)
head(france.geodata)
##   id mapvariable
## 1  0  1.12200636
## 2  1  0.05912043
## 3  2 -1.05873510
## 4  3 -1.31513865
## 5  4  0.32392954
## 6  5  0.09152878

Use ggmap

# fortify prepares the shape data for ggplot
france.dataframe <- fortify(fr.prj) # convert to data frame for ggplot
## Regions defined for each Polygons
head(france.dataframe)
##       long      lat order  hole piece id group
## 1 7.847912 49.04728     1 FALSE     1  0   0.1
## 2 7.844539 49.04495     2 FALSE     1  0   0.1
## 3 7.852439 49.04510     3 FALSE     1  0   0.1
## 4 7.854333 49.04419     4 FALSE     1  0   0.1
## 5 7.855955 49.04431     5 FALSE     1  0   0.1
## 6 7.856299 49.03776     6 FALSE     1  0   0.1
#now combine the values by id values in both dataframes
france.dat <- join(france.geodata, france.dataframe, by="id")
head(france.dat)
##   id mapvariable     long      lat order  hole piece group
## 1  0    1.122006 7.847912 49.04728     1 FALSE     1   0.1
## 2  0    1.122006 7.844539 49.04495     2 FALSE     1   0.1
## 3  0    1.122006 7.852439 49.04510     3 FALSE     1   0.1
## 4  0    1.122006 7.854333 49.04419     4 FALSE     1   0.1
## 5  0    1.122006 7.855955 49.04431     5 FALSE     1   0.1
## 6  0    1.122006 7.856299 49.03776     6 FALSE     1   0.1
# Plot 3
p <- ggplot(data=france.dat, aes(x=long, y=lat, group=group))
p <- p + geom_polygon(aes(fill=mapvariable)) +
       geom_path(color="white",size=0.1) +
       coord_equal() +
       scale_fill_gradient(low = "#ffffcc", high = "#ff4444") +
       labs(title="Our map",fill="My variable")
# plot the map
p

image-22-02-2017-at-12-11

Use plot basic

nclassint <- 5 #number of colors to be used in the palette
cat <- classIntervals(myvar, nclassint,style = "jenks") #style refers to how the breaks are created
colpal <- brewer.pal(nclassint,"RdBu")
color <- findColours(cat,rev(colpal)) #sequential
bins <- cat$brks
lb <- length(bins)
plot(fr.prj, col=color,border=T)
legend("bottomleft",fill=rev(colpal),legend=paste(round(bins[-length(bins)],1),":",round(bins[-1],1)),cex=1, bg="white")

image-22-02-2017-at-12-23-copy