The Data
The code
#
# This is code for mapping of CGE_Morocco results
#
# rm(list = ls(all = TRUE)) # don't use this in code that others will copy/paste
## Loading packages
library(rgdal)
library(plyr)
library(maps)
library(maptools)
library(mapdata)
library(ggplot2)
library(RColorBrewer)
## Loading shape files administrative coordinates for Morocco maps
#Morocco <- readOGR(dsn=".", layer="Morocco_adm0")
MoroccoReg <- readOGR(dsn=".", layer="Morocco_adm1")
## Reorder the data in the shapefile based on the regional order
MoroccoReg <- MoroccoReg[order(MoroccoReg$ID_1), ]
## Add the yield impacts column to shapefile
MoroccoReg@data$SRESB2_CO2 <- c(0.003,0.100,0.116,-0.105,-0.010,0.048,0.006,-0.004,0.061,0.032,0.003,-0.016,-0.018,0.095)
## Check the structure and contents of shapefile
summary(MoroccoReg)
attributes(MoroccoReg)
## Plotting
MoroccoRegMap <- ggplot(data = MoroccoReg, aes(long, lat, group = group))
MoroccoRegMap <- MoroccoRegMap + geom_polygon()
MoroccoRegMap <- MoroccoRegMap + geom_path(colour = 'gray', linestyle = 2)
MoroccoRegMap <- MoroccoRegMap + scale_fill_brewer('ID_1')
MoroccoRegMap <- MoroccoRegMap + coord_equal() + theme_bw()
MoroccoRegMap
The plot
The Question is two fold: First, I am looking to be able to color each region separately. Second, I want to do that based on each region's projected yield impact as captured by the variable "SRESB2_CO2" in the data.
Thanks in advance for the help.
Here is the additional yield data in .csv format, code and results.
Yield data: Data
Code:
Results: