diff --git a/R/format.data/BCI.R b/R/format.data/BCI.R index a64b9a070424597dee0be0d8428c116ea749b686..e6eaaa936453bb13140c67c836bf0f2d8c1dc2ef 100644 --- a/R/format.data/BCI.R +++ b/R/format.data/BCI.R @@ -77,5 +77,7 @@ vec.basic.var <- c("obs.id","tree.id", "sp", "sp.name","plot", "subplot", "D", " "year", "htot", "x", "y", "census") data.tree <- subset(data.bci, select = c(vec.basic.var)) - +data.tree[["Lon"]] <- -79.8461 +data.tree[["Lat"]] <- 9.1543 +data.tree[["ecocode"]] <- "tropical" write.csv(data.tree,file="output/formatted/BCI/tree.csv",row.names = FALSE) diff --git a/R/format.data/Fushan.R b/R/format.data/Fushan.R index b2cd1ac7e0f4879359ee5cc8cf7c7d9dc8546718..c237a67dda0e83c40a093e7197201f050e4aa412 100644 --- a/R/format.data/Fushan.R +++ b/R/format.data/Fushan.R @@ -45,6 +45,11 @@ data.fushan <- subset(data.fushan,subset=data.fushan$status1!="P") vec.basic.var <- c("obs.id","tree.id", "sp", "sp.name","plot", "subplot", "D", "G", "dead", "year", "htot", "x", "y", "census") data.tree <- subset(data.fushan, select = c(vec.basic.var)) + +data.tree[["Lon"]] <- 121.555 +data.tree[["Lat"]] <- 24.7614 +data.tree[["ecocode"]] <- "tropical" + write.csv(data.tree,file="output/formatted/Fushan/tree.csv",row.names = FALSE) diff --git a/R/format.data/Paracou.R b/R/format.data/Paracou.R index 60457745124cb6b3e24afe1798caa7451beb8d66..98bf88b215b8eb4b4685302744b5e4dccf4e4991 100644 --- a/R/format.data/Paracou.R +++ b/R/format.data/Paracou.R @@ -95,6 +95,11 @@ data.paracou$sp.name <- data.paracou$Latin_name vec.basic.var <- c("obs.id","tree.id", "sp", "sp.name","plot", "subplot", "D", "G", "dead", "year", "htot", "x", "y", "census") data.tree <- subset(data.paracou, select = c(vec.basic.var)) + +data.tree[["Lon"]] <- -52.900002 +data.tree[["Lat"]] <- 5.38 +data.tree[["ecocode"]] <- "tropical" + write.csv(data.tree,file="output/formatted/Paracou/tree.csv",row.names = FALSE) diff --git a/R/process.data/analysis.R b/R/process.data/analysis.R index ad760c78f48040124b1ba4d5fb1a92a488db321e..06a13f0a8a72d587e8ffb0b27eb6f65bb3ea4ebe 100644 --- a/R/process.data/analysis.R +++ b/R/process.data/analysis.R @@ -2,8 +2,9 @@ ############################################# MERGE FRENCH DATA path.formatted <- "output/formatted" path.processed <- "output/processed" +library(plyr) -source("analysis-fun.R") +source("R/process.data/analysis-fun.R") ## load all sites data <- load_all_formatted_data(path.formatted) @@ -11,32 +12,19 @@ data <- load_all_formatted_data(path.formatted) source("R/utils/plot.R") source("R/utils/maps.R") -# Map for single site -# to.dev(world.map(data[["US"]]$tree[["Lon"]], data[["US"]]$tree[["Lat"]], group = NULL, cols = NULL), -# png,file="map.png", height =800, width = 800) +get_unique_plot_coords <- function(set, data){ + i <- !duplicated(paste(data[[set]]$tree$Lon, data[[set]]$tree$Lat)) #find duplicates + data.frame(set = set, Lon = data[[set]]$tree$Lon[i], Lat = data[[set]]$tree$Lat[i], ecocode = data[[set]]$tree$ecocode[i], stringsAsFactors=FALSE) +} + +x <- rbind.fill(lapply(names(data), get_unique_plot_coords, data=data)) # Map for all sites -to.dev(world.map.all.sites(data), +to.dev(world.map.all.sites(x, add.legend =TRUE), png,file=file.path(path.processed, "world_map_all.png"), height =2000, width = 2000) -png("output/figs/world.map.all.png",height=2000,width=2000) -world.map.all.sites(data,legend.TF=FALSE) -BCI <- c(-79.8461,9.1543) -Paracou <- c(-52.900002,5.38) -Fushan <- c(121.555 , 24.7614) -NSW <- c(151,-33.18) -data.bigplot <- rbind(BCI,Paracou,Fushan,NSW) -points(data.bigplot[,1],data.bigplot[,2],col="red",cex=3,pch=16) - -M_baiki <- c(17.93,3.9) -Luquillo <- c(-65.816,18.3262) -La_chonta <- c(-62.99,-15.75) -data.bigplot.add <- rbind(M_baiki,Luquillo,La_chonta) -points(data.bigplot.add[,1],data.bigplot.add[,2],col="green",cex=3,pch=16) -dev.off() # make summary table -library(plyr) data.summary <- lapply(data, summarise.data) tab.1 <- rbind.fill(lapply(data.summary,summary.table.1)) diff --git a/R/utils/maps.R b/R/utils/maps.R index 0253f25b99443bb7824ad1f6f25513adca61a180..db2ebe9764c9d4181271b99499368094f9fe9275 100644 --- a/R/utils/maps.R +++ b/R/utils/maps.R @@ -3,47 +3,35 @@ library(rworldmap, quietly = TRUE) ## Plot map of distn -world.map <- function(Lon, Lat, group = NULL, cols = NULL, add = FALSE,legend.TF=FALSE){ +world.map <- function(Lon, Lat, col = "red", add = FALSE, cex=0.2){ if(!add){ newmap <- getMap(resolution = 'low') plot(newmap, col= "lightgrey") } - if(is.null(group)) - group <- rep("all", length(Lat)) - - ngrps <- length(unique(group)) - - if(is.null(cols)) #establish new pallettte if needed - cols <- brewer.pal(max(ngrps,3), "Set1") - else # check enough cols for groups - if(length(cols) < ngrps) - cols <- rep(cols[1], ngrps) - - # add data, unique points only - i <- !duplicated(paste(Lon, Lat, group)) - - points(Lon[i],Lat[i],pty='.',cex=.2, col = cols[as.factor(group)]) - - if(legend.TF){ - legend('bottomleft', col = cols, legend = names(table(group)), pch = rep(19,ngrps), bty = "n") - } + points(Lon,Lat,pch=19,cex=cex, col = col) } -world.map.all.sites <- function(data,legend.TF=FALSE){ - +world.map.all.sites <- function(data,add.legend=FALSE){ + +sets <- unique(data$set) + # list of colours -cols <- as.list(niceColors(length(data)) ) -names(cols) <- names(data) +cols <- as.list(niceColors(length(sets))) +names(cols) <- sets # new map -world.map(NA, NA, group = NULL, cols = NULL) +world.map(NA, NA) -for(site in names(data)) - world.map(data[[site]]$tree[["Lon"]], data[[site]]$tree[["Lat"]], group = NULL, col = cols[[site]], add=TRUE,legend.TF) - if(legend.TF){ - legend('bottomleft', col = unlist(cols), legend = names(cols), pch = rep(19,length(cols)), bty = "n") +for(set in sets){ + i <- data$set ==set + cex = 0.4 + if(sum(i) ==1) + cex=2 + world.map(data[i, "Lon"], data[i, "Lat"], col = cols[[set]], add=TRUE, cex=cex) } +if(add.legend) + legend('bottomleft', col = unlist(cols), legend = names(cols), pch = rep(19,length(cols)), bty = "n") } diff --git a/data/metadata/sites/Fushan/_site_details.JSON b/data/metadata/sites/Fushan/_site_details.JSON index 0f9d8a93f727f78959bc9db75796263e5cff6c6d..e3a1bda099ee07371d3546c71f2120179a5b6a5f 100644 --- a/data/metadata/sites/Fushan/_site_details.JSON +++ b/data/metadata/sites/Fushan/_site_details.JSON @@ -10,8 +10,8 @@ "country": "Taiwan", "climate": "", "vegetation type": "", - "latitude": -1, - "longitude": -1, + "latitude": 24.7614, + "longitude": 121.555, "minimum tree size": "", "history": "", "field methodology": "",