title: “G4D- Asignment No 1(i)” author: “Miriam Kasebele” date: “31 10 2018” output: html_document: df_print: paged

Introduction This is an R Markdown Notebook aimed at learning how to make thematic maps. It is based on the cartography R package developed by Timothée Giraud as well as on code written by Bhaskar Karambelkar.

The G4D Assignment No. 1 comprises two tasks: (i) to reproduce and publish a notebook similar to this one; and (ii) to add new examples of R mapping functionalities to the notebook based on the geospatial data processing skills learned at Data Camp. The assignment can be done using RStudio Cloud (for editing the document) and RPubs (for publishing the document).

Static Mapping

library(rgdal)
## Loading required package: sp
## rgdal: version: 1.3-6, (SVN revision 773)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
##  Path to GDAL shared files: /usr/share/gdal/2.1
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.3-1
library(sf)
## Linking to GEOS 3.5.1, GDAL 2.1.3, PROJ 4.9.2
library(sp)
library(cartography)
library(rgdal)
###  getting vector data
download.file("http://data.biogeo.ucdavis.edu/data/diva/adm/TZA_adm.zip", 
destfile = "./data/TZA_adm.zip" , mode='wb')
unzip("./data/TZA_adm.zip", exdir = "./data")
spcol <- readOGR(dsn = "./data/TZA_adm1.shp", verbose = FALSE)
class(spcol)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
spcol@data$COLOUR <- "#FFFFFF"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 0] <- "#006837"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 1] <- "#52BE80"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 2] <- "#28B463"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 3] <- "#D4EFDF"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 4] <- "#138D75"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 5] <- "#76D7C4"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 6] <- "#A3E4D7"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 7] <- "#D0ECE7"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 8] <- "#FAE5D3"
spcol@data$COLOUR[(as.numeric(as.character(spcol@data$ID_1)) %% 10) == 9] <- "#A9CCE3"

plot(spcol, col=spcol$COLOUR, main = "Tanzania's Departments")

library(sf)

sfcol <- st_read(dsn = "./data/TZA_adm1.shp", quiet = TRUE)
class(sfcol)
## [1] "sf"         "data.frame"
sfcol$COLOUR <- spcol@data$COLOUR

plot(st_geometry(sfcol), col=sfcol$COLOUR, main = "Tanzania's Departments")

oldw <- getOption("warn")
options(warn = -1)

options(warn = oldw)
library(cartography)
data(nuts2006)
plot(nuts0.spdf, border = NA, col = NA, bg = "#A6CAE0")
# Plot non european space
plot(world.spdf, col  = "#E3DEBF", border=NA, add=TRUE)
# Plot a layer of countries borders
plot(nuts0.spdf, border = "grey20", lwd = 3, add = TRUE)
# Plot a layer of NUTS1
plot(nuts1.spdf, border = "grey30", lwd = 2, add = TRUE)
# Plot a layer of NUTS2
plot(nuts2.spdf, border = "grey40", lwd = 0.5, add = TRUE)
# Plot a layer of NUTS3
plot(nuts3.spdf, border = "grey20", lwd = 0.1, add = TRUE)

# Layout plot
layoutLayer(title = "Most Populated Countries in Europe", # title of the map
            author = "Author:Miriam Kasebele",  # 
            sources = "Sources: Eurostat", # 
            scale = NULL, # no scale
            col = NA, # no color for the title box 
            coltitle = "black", # color of the title
            frame = TRUE, 
            bg = "#A6CAE0", # background of the map
            extent = nuts0.spdf) # set the extent of the map

# Non European space
plot(world.spdf, col = "#AAB7B8", border = NA, add = TRUE)
# European (EU28) countries
plot(nuts0.spdf, col = "#F12BD0",border = "white", lwd = 1, add = TRUE)

# Selection of the 10 most populated countries of Europe
dflab <- nuts0.df[order(nuts0.df$pop2008, decreasing = TRUE),][1:10,]
# Label creation
dflab$lab <- paste(dflab$id, "\n", round(dflab$pop2008/1000000,0), "M", sep ="")

# Label plot of the 10 most populated countries
labelLayer(spdf = nuts0.spdf, # SpatialPolygonsDataFrame used to plot he labels
           df = dflab, # data frame containing the lables
           txt = "lab", # label field in df
           col = "#690409", # color of the labels
           cex = 0.6, # size of the labels
           font = 2) # label font

# Add an explanation text
text(x = 5477360, y = 4177311, labels = "The 10 most populated countries of Europe
Total population 2008 [millions]", cex = 0.7, adj = 0)

# Compute the compound annual growth rate
nuts2.df$cagr <- (((nuts2.df$pop2008 / nuts2.df$pop1999)^(1/9)) - 1) * 100

# Set a custom color palette
cols <- carto.pal(pal1 = "green.pal", # first color gradient
                  n1 = 2, # number of colors in the first gradiant
                  pal2 = "red.pal", # second color gradient
                  n2 = 4) # number of colors in the second gradiant

# Plot a layer with the extent of the EU28 countries with only a background color
plot(nuts0.spdf, border = NA, col = NA, bg = "#A6CAE0")
# Plot non european space
plot(world.spdf, col  = "#E3DEBF", border=NA, add=TRUE)

# Plot the compound annual growth rate
choroLayer(spdf = nuts2.spdf, # SpatialPolygonsDataFrame of the regions
           df = nuts2.df, # data frame with compound annual growth rate
           var = "cagr", # compound annual growth rate field in df
           breaks = c(-2.43,-1,0,0.5,1,2,3.1), # list of breaks
           col = cols, # colors 
           border = "grey40", # color of the polygons borders
           lwd = 0.5, # width of the borders
           legend.pos = "right", # position of the legend
           legend.title.txt = "Compound Annual\nGrowth Rate", # title of the legend
           legend.values.rnd = 2, # number of decimal in the legend values
           add = TRUE) # add the layer to the current plot

# Plot a layer of countries borders
plot(nuts0.spdf,border = "grey20", lwd=0.75, add=TRUE)

# Layout plot
layoutLayer(title = "Demographic Trends", author = "cartography", 
            sources = "Eurostat, 2008", frame = TRUE, col = NA, 
            scale = NULL,coltitle = "black",
            south = TRUE) # add a south arrow

##Interactive Mapping

library(ggplot2)
library(ggiraph)
library(rnaturalearth)
library(readr)
library(RCurl)
## Loading required package: bitops

###Loading required bitops

urlfile <- "https://raw.github.com/bhaskarvk/user2017.geodataviz/master/inst/extdata/africa-internet_usage-2015.csv"

internet_usage <- read.csv(urlfile)

head(internet_usage)
##   Country.Name Country.Code
## 1      Algeria          DZA
## 2       Angola          AGO
## 3      Bahrain          BHR
## 4        Benin          BEN
## 5     Botswana          BWA
## 6 Burkina Faso          BFA
##                                        Series.Name    Series.Code
## 1 Individuals using the Internet (% of population) IT.NET.USER.ZS
## 2 Individuals using the Internet (% of population) IT.NET.USER.ZS
## 3 Individuals using the Internet (% of population) IT.NET.USER.ZS
## 4 Individuals using the Internet (% of population) IT.NET.USER.ZS
## 5 Individuals using the Internet (% of population) IT.NET.USER.ZS
## 6 Individuals using the Internet (% of population) IT.NET.USER.ZS
##   X2014..YR2014. X2015..YR2015. X2016..YR2016.
## 1       25.00000      38.200000             ..
## 2       10.20000      12.400000             ..
## 3       90.50313      93.478301             ..
## 4        6.00000       6.787703             ..
## 5       18.50000      27.500000             ..
## 6        9.40000      11.387646             ..
names(internet_usage) <- c("Country Name",  "Country Code",   "Series Name",  "Series Code", 
"2014 [YR2014]", "2015 [YR2015]", "2015 [YR20156]")


names(internet_usage)
## [1] "Country Name"   "Country Code"   "Series Name"    "Series Code"   
## [5] "2014 [YR2014]"  "2015 [YR2015]"  "2015 [YR20156]"
world <- sf::st_as_sf(rnaturalearth::countries110)
##str(world)
length(unique(world$iso_a3))
## [1] 175
africa <- dplyr::filter(world, region_un=='Africa') %>%
  dplyr::left_join(internet_usage %>% dplyr::select(
    `Country Code`, `2015 [YR2015]`
  ) %>% dplyr::rename("iso_a3"=`Country Code`, internet.usage.2015=`2015 [YR2015]`),
  by = 'iso_a3') %>%
  st_transform(crs="+proj=laea +lon_0=18.984375")
## Warning: Column `iso_a3` joining character vector and factor, coercing into
## character vector
head(africa)
## Simple feature collection with 6 features and 64 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -2664406 ymin: -2941948 xmax: 1306017 ymax: 1690992
## epsg (SRID):    NA
## proj4string:    +proj=laea +lat_0=0 +lon_0=18.984375 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs
##   scalerank      featurecla labelrank               sovereignt sov_a3
## 1         1 Admin-0 country         3                   Angola    AGO
## 2         1 Admin-0 country         6                  Burundi    BDI
## 3         1 Admin-0 country         5                    Benin    BEN
## 4         1 Admin-0 country         3             Burkina Faso    BFA
## 5         1 Admin-0 country         4                 Botswana    BWA
## 6         1 Admin-0 country         4 Central African Republic    CAF
##   adm0_dif level              type                    admin adm0_a3
## 1        0     2 Sovereign country                   Angola     AGO
## 2        0     2 Sovereign country                  Burundi     BDI
## 3        0     2 Sovereign country                    Benin     BEN
## 4        0     2 Sovereign country             Burkina Faso     BFA
## 5        0     2 Sovereign country                 Botswana     BWA
## 6        0     2 Sovereign country Central African Republic     CAF
##   geou_dif                  geounit gu_a3 su_dif                  subunit
## 1        0                   Angola   AGO      0                   Angola
## 2        0                  Burundi   BDI      0                  Burundi
## 3        0                    Benin   BEN      0                    Benin
## 4        0             Burkina Faso   BFA      0             Burkina Faso
## 5        0                 Botswana   BWA      0                 Botswana
## 6        0 Central African Republic   CAF      0 Central African Republic
##   su_a3 brk_diff                 name                name_long brk_a3
## 1   AGO        0               Angola                   Angola    AGO
## 2   BDI        0              Burundi                  Burundi    BDI
## 3   BEN        0                Benin                    Benin    BEN
## 4   BFA        0         Burkina Faso             Burkina Faso    BFA
## 5   BWA        0             Botswana                 Botswana    BWA
## 6   CAF        0 Central African Rep. Central African Republic    CAF
##               brk_name brk_group abbrev postal                   formal_en
## 1               Angola      <NA>   Ang.     AO People's Republic of Angola
## 2              Burundi      <NA>   Bur.     BI         Republic of Burundi
## 3                Benin      <NA>  Benin     BJ           Republic of Benin
## 4         Burkina Faso      <NA>   B.F.     BF                Burkina Faso
## 5             Botswana      <NA>   Bwa.     BW        Republic of Botswana
## 6 Central African Rep.      <NA> C.A.R.     CF    Central African Republic
##   formal_fr note_adm0 note_brk                name_sort name_alt mapcolor7
## 1      <NA>      <NA>     <NA>                   Angola     <NA>         3
## 2      <NA>      <NA>     <NA>                  Burundi     <NA>         2
## 3      <NA>      <NA>     <NA>                    Benin     <NA>         1
## 4      <NA>      <NA>     <NA>             Burkina Faso     <NA>         2
## 5      <NA>      <NA>     <NA>                 Botswana     <NA>         6
## 6      <NA>      <NA>     <NA> Central African Republic     <NA>         5
##   mapcolor8 mapcolor9 mapcolor13  pop_est gdp_md_est pop_year lastcensus
## 1         2         6          1 12799293     110300       NA       1970
## 2         2         5          8  8988091       3102       NA       2008
## 3         2         2         12  8791832      12830       NA       2002
## 4         1         5         11 15746232      17820       NA       2006
## 5         5         7          3  1990876      27060       NA       2011
## 6         6         6          9  4511488       3198       NA       2003
##   gdp_year                   economy             income_grp wikipedia
## 1       NA 7. Least developed region 3. Upper middle income        NA
## 2       NA 7. Least developed region          5. Low income        NA
## 3       NA 7. Least developed region          5. Low income        NA
## 4       NA 7. Least developed region          5. Low income        NA
## 5       NA      6. Developing region 3. Upper middle income        NA
## 6       NA 7. Least developed region          5. Low income        NA
##   fips_10 iso_a2 iso_a3 iso_n3 un_a3 wb_a2 wb_a3 woe_id adm0_a3_is
## 1    <NA>     AO    AGO    024   024    AO   AGO     NA        AGO
## 2    <NA>     BI    BDI    108   108    BI   BDI     NA        BDI
## 3    <NA>     BJ    BEN    204   204    BJ   BEN     NA        BEN
## 4    <NA>     BF    BFA    854   854    BF   BFA     NA        BFA
## 5    <NA>     BW    BWA    072   072    BW   BWA     NA        BWA
## 6    <NA>     CF    CAF    140   140    CF   CAF     NA        CAF
##   adm0_a3_us adm0_a3_un adm0_a3_wb continent region_un       subregion
## 1        AGO         NA         NA    Africa    Africa   Middle Africa
## 2        BDI         NA         NA    Africa    Africa  Eastern Africa
## 3        BEN         NA         NA    Africa    Africa  Western Africa
## 4        BFA         NA         NA    Africa    Africa  Western Africa
## 5        BWA         NA         NA    Africa    Africa Southern Africa
## 6        CAF         NA         NA    Africa    Africa   Middle Africa
##            region_wb name_len long_len abbrev_len tiny homepart
## 1 Sub-Saharan Africa        6        6          4   NA        1
## 2 Sub-Saharan Africa        7        7          4   NA        1
## 3 Sub-Saharan Africa        5        5          5   NA        1
## 4 Sub-Saharan Africa       12       12          4   NA        1
## 5 Sub-Saharan Africa        8        8          4   NA        1
## 6 Sub-Saharan Africa       20       24          6   NA        1
##   internet.usage.2015                       geometry
## 1           12.400000 MULTIPOLYGON (((-294686.1 -...
## 2            4.866224 MULTIPOLYGON (((1148567 -49...
## 3            6.787703 MULTIPOLYGON (((-1799514 69...
## 4           11.387646 MULTIPOLYGON (((-2387715 10...
## 5           27.500000 MULTIPOLYGON (((712546.6 -2...
## 6            4.563264 MULTIPOLYGON (((-409783.7 8...
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
x<-data.frame(a=letters[1:7])
y<-data.frame(a=letters[4:10])

class(x$a) 
## [1] "factor"
# [1] "factor"

# NOTE these are different
levels(x$a)
## [1] "a" "b" "c" "d" "e" "f" "g"
# [1] "a" "b" "c" "d" "e" "f" "g"
levels(y$a)
## [1] "d" "e" "f" "g" "h" "i" "j"
# [1] "d" "e" "f" "g" "h" "i" "j"
m <- left_join(x,y)
## Joining, by = "a"
## Warning: Column `a` joining factors with different levels, coercing to
## character vector
# Joining by: "a"
# Warning message:
# joining factors with different levels, coercing to character vector 

class(m$a)
## [1] "character"
# [1] "character"
africa.centers <- st_centroid(africa)
## Warning in st_centroid.sf(africa): st_centroid assumes attributes are
## constant over geometries of x
africa.spdf <- methods::as(africa, 'Spatial')
africa.spdf@data$id <- row.names(africa.spdf@data)

africa.tidy <- broom::tidy(africa.spdf)
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector,
## coercing into character vector
## Regions defined for each Polygons
oldw <- getOption("warn")
options(warn = -1)

options(warn = oldw)
library(htmlwidgets)
library(hrbrthemes)
africa.tidy <- dplyr::left_join(africa.tidy, africa.spdf@data, by='id')

``

g <- ggplot(africa.tidy) +
  geom_polygon_interactive(
    color='black',
    aes(long, lat, group=group, fill=internet.usage.2015,
        tooltip=sprintf("%s<br/>%s",iso_a3,internet.usage.2015))) +
 hrbrthemes::theme_ipsum() +
  colormap::scale_fill_colormap(
    colormap=colormap::colormaps$copper, reverse = T) +
  labs(title='Internet Usage in Africa in 2015', subtitle='As Percent of Population',
       caption='Source: World Bank Open Data.')