install.packages(“ggplot2”) install.packages(“ggmaps”) install.packages(“rgdal”) install.packages(“rgeos”) install.packages(“sp”) install.packages(“shapefiles”) install.packages(“ggmap”) install.packages(“dplyr”) install.packages(“plyr”) library(dplyr) library(plyr) library(ggplot2) library(ggmaps) library(rgdal) library(rgeos) library(sp) library(shapefiles) library(ggmap)

require(dplyr) require(plyr) require(ggplot2) require(ggmaps) require(rgdal) require(rgeos) require(sp) require(shapefiles) require(ggmap)

counties <- readOGR(dsn=“Liberia_Dean”, layer=“counties”, stringsAsFactors=FALSE, verbose=FALSE)

proj4string(counties)

counties <- spTransform(counties, CRS(“+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0”))

counties_f <- fortify(counties, region = “CCNAME”)

liberia <- get_map(location = c(-11.65, 4.25, -7.25, 8.6), maptype = “watercolor”)

liberia <- ggmap(liberia)

lbr_counties <- liberia + geom_map(data=country_f,map=country_f,aes(x=long, y=lat, map_id=id),color =“white”, alpha = 0, size = .6)

lbr_counties <- lbr_counties + geom_map(data=counties_f,map=counties_f,aes(x=long, y=lat, map_id=id),color =“white”, fill = “orangered”, alpha = .5, size = .3)

lbr_counties <- lbr_counties + ggtitle(“Total Population (in 1000s)”)

trueCentroids = gCentroid(counties,byid=TRUE)

plot(counties)

points(coordinates(counties))

CountyPointsDF<- merge(counties_f, counties@data, by = “id”)

countiesName = counties@data$CCNAME

vecCounties = cbind.data.frame(trueCentroids, countiesName)

lbr_counties <- lbr_counties + annotate(‘text’, x = vecCountiesx,y=vecCountiesy,label =

vecCounties$countiesName, size = 2)

counties_f <- left_join(x = counties_f, y = counties@data, by = c(“id” = “CCNAME”))

lbr_cnty_pop <- lbr_counties + geom_map(data=counties_f,map=counties_f,aes(x=long, y=lat,map_id=id, fill =SUM_TOTAL/1000), color =“white”, alpha = .5, size = .1)

lbr_cnty_pop <- lbr_cnty_pop + scale_fill_gradient2(low = “blue”, mid=“yellow”, high=“red”,midpoint = 600, space=“Lab”, guide = guide_legend(title = NULL))

lbr_cnty_pop

Total Population (in 1000s).

Total Population (in 1000s).

// Person per KM2

lbr_counties <- lbr_counties + ggtitle(“Persons per km2”)

lbr_cnty_Density <- lbr_counties + geom_map(data=counties_f,map=counties_f,aes(x=long, y=lat,map_id=id, fill = SUM_TOTAL / Sq_km), color =“white”, alpha = .5, size = .1)

lbr_cnty_Density <- lbr_cnty_Density + scale_fill_gradient2(low = “blue”, mid=“yellow”, high=“red”,midpoint = 600, space=“Lab”, guide = guide_legend(title = NULL))

Total Persons per km2.

Total Persons per km2.

//Percent Female lbr_counties <- lbr_counties + ggtitle(“Percent Female”)

lbr_cnty_FemalePer <- lbr_counties + geom_map(data=counties_f,map=counties_f,aes(x=long, y=lat,map_id=id, fill = SUM_FEMALE / SUM_TOTAL), color =“white”, alpha = .5, size = .1)

lbr_cnty_FemalePer <- lbr_cnty_FemalePer + scale_fill_gradient2(low = “blue”, mid=“yellow”, high=“red”,midpoint = 600, space=“Lab”, guide = guide_legend(title = NULL))

lbr_cnty_FemalePer

lbr_cnty_FemalePer <- lbr_cnty_FemalePer + scale_fill_gradient(low = “blue”, high=“red”, space=“Lab”, + guide = guide_legend(title = NULL))

lbr_cnty_FemalePer

Total Percent of Females.

Total Percent of Females.

// Persons per household

lbr_counties <- lbr_counties + ggtitle(“Persons per Household”)

lbr_cnty_HH <- lbr_counties + geom_map(data=counties_f,map=counties_f,aes(x=long, y=lat,map_id=id, fill = SUM_TOTAL / SUM_HH), color =“white”, alpha = .5, size = .1)

lbr_cnty_HH <- lbr_cnty_HH + scale_fill_gradient(low = “blue”, high=“red”, space=“Lab”,guide = guide_legend(title = NULL))

lbr_cnty_HH Total Persons per Household.

Total Persons per Household.

Total Persons per Household.