# align data extracted by Had #library(rgdal) library(terra) library(sf) # Layers # 1. Cassava production # 2. Harvest Area # 3. ls population 2014 # 4. settlement 2018 # extracted at 2km, 5km and 10km buffers # Point buffers. # original outputs had each settlement layer stacked with labels in betwen. Manually manipulated these to be in wide format CIV_buff_pointstats_max <- read.csv("CIV_buff_pointstats_wide_max.csv", header=TRUE, skip=2) CIV_buff_pointstats_min <- read.csv("CIV_buff_pointstats_wide_min.csv", header=TRUE, skip=2) CIV_buff_pointstats_mean <- read.csv("CIV_buff_pointstats_wide_mean.csv", header=TRUE, skip=2) CIV_buff_pointstats_sd <- read.csv("CIV_buff_pointstats_wide_sd.csv", header=TRUE, skip=2) CIV_buff_pointstats_sum <- read.csv("CIV_buff_pointstats_wide_sum.csv", header=TRUE, skip=2) CIV_buff_pointstats_quantile <- read.csv("CIV_buff_pointstats_wide_quantile.csv", header=TRUE, skip=2) UGA_buff_pointstats_max <- read.csv("UGA_buff_pointstats_wide_max.csv", header=TRUE, skip=2) UGA_buff_pointstats_min <- read.csv("UGA_buff_pointstats_wide_min.csv", header=TRUE, skip=2) UGA_buff_pointstats_mean <- read.csv("UGA_buff_pointstats_wide_mean.csv", header=TRUE, skip=2) UGA_buff_pointstats_sd <- read.csv("UGA_buff_pointstats_wide_sd.csv", header=TRUE, skip=2) UGA_buff_pointstats_sum <- read.csv("UGA_buff_pointstats_wide_sum.csv", header=TRUE, skip=2) UGA_buff_pointstats_quantile <- read.csv("UGA_buff_pointstats_wide_quantile.csv", header=TRUE, skip=2) # tidy these up, by removing multiple sample ids and merging together per country CIV_buff_pointstats_max[, seq(from=3, by=2, to=23)] <- NULL CIV_buff_pointstats_min[, seq(from=3, by=2, to=23)] <- NULL CIV_buff_pointstats_mean[, seq(from=3, by=2, to=23)] <- NULL CIV_buff_pointstats_sd[, seq(from=3, by=2, to=23)] <- NULL CIV_buff_pointstats_sum[, seq(from=3, by=2, to=23)] <- NULL CIV_buff_pointstats_quantile[, seq(from=7, by=6, to=72)] <- NULL names(CIV_buff_pointstats_max) <- c("SampleID", paste("max_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(CIV_buff_pointstats_min) <- c("SampleID", paste("min_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(CIV_buff_pointstats_mean) <- c("SampleID", paste("mean_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(CIV_buff_pointstats_sd) <- c("SampleID", paste("sd_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(CIV_buff_pointstats_sum) <- c("SampleID", paste("sum_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(CIV_buff_pointstats_quantile) <- c("SampleID", paste(rep(c("min", "lowerQ", "median", "upperQ", "max"), times=4*3), rep(c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), each=5), sep="_")) CIV_buff_pointstats <- merge(CIV_buff_pointstats_mean, CIV_buff_pointstats_sd, by="SampleID") CIV_buff_pointstats <- merge(CIV_buff_pointstats, CIV_buff_pointstats_sum, by="SampleID") CIV_buff_pointstats <- merge(CIV_buff_pointstats, CIV_buff_pointstats_quantile, by="SampleID") dim(CIV_buff_pointstats) UGA_buff_pointstats_max[, seq(from=3, by=2, to=23)] <- NULL UGA_buff_pointstats_min[, seq(from=3, by=2, to=23)] <- NULL UGA_buff_pointstats_mean[, seq(from=3, by=2, to=23)] <- NULL UGA_buff_pointstats_sd[, seq(from=3, by=2, to=23)] <- NULL UGA_buff_pointstats_sum[, seq(from=3, by=2, to=23)] <- NULL UGA_buff_pointstats_quantile[, seq(from=7, by=6, to=72)] <- NULL names(UGA_buff_pointstats_max) <- c("SampleID", paste("max_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(UGA_buff_pointstats_min) <- c("SampleID", paste("min_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(UGA_buff_pointstats_mean) <- c("SampleID", paste("mean_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(UGA_buff_pointstats_sd) <- c("SampleID", paste("sd_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(UGA_buff_pointstats_sum) <- c("SampleID", paste("sum_", c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), sep="")) names(UGA_buff_pointstats_quantile) <- c("SampleID", paste(rep(c("min", "lowerQ", "median", "upperQ", "max"), times=4*3), rep(c("Prod.2000", "Prod.5000", "Prod.10000", "Harv.2000", "Harv.5000", "Harv.10000", "lspop.2000", "lspop.5000", "lspop.10000", "settle.2000", "settle.5000", "settle.10000"), each=5), sep="_")) UGA_buff_pointstats <- merge(UGA_buff_pointstats_mean, UGA_buff_pointstats_sd, by="SampleID") UGA_buff_pointstats <- merge(UGA_buff_pointstats, UGA_buff_pointstats_sum, by="SampleID") UGA_buff_pointstats <- merge(UGA_buff_pointstats, UGA_buff_pointstats_quantile, by="SampleID") dim(UGA_buff_pointstats) # check long and lat of the sample points CIV_pnts = st_read(dsn="cassava_wip.gdb",layer=paste0("CIV","_centroids")) CIV_pnts$SampleID <- 1:nrow(CIV_pnts) CIV_buff_pointstats <- merge(CIV_buff_pointstats, CIV_pnts[, c("SampleID", "Centre_Lon", "Centre_Lat")], by="SampleID") UGA_pnts = st_read(dsn="cassava_wip.gdb",layer=paste0("UGA","_centroids")) UGA_pnts$SampleID <- 1:nrow(UGA_pnts) UGA_buff_pointstats <- merge(UGA_buff_pointstats, UGA_pnts[, c("SampleID", "Centre_Lon", "Centre_Lat")], by="SampleID") rm(list=ls()[which(!(ls()%in%c("CIV_buff_pointstats","UGA_buff_pointstats","civ","uga","dat_civ","dat_uga")))])