Commit 4aab3f5f authored by peguerin's avatar peguerin
Browse files

table to request

parent 627b9297
###############################################################################
# functions
## from center of square coordinate (h,k) and length L return corner coordinates
corners_of_square <- function(cells,L) {
corners=data.frame(
lng1=cells$x-L/2,
lat1=cells$y+L/2,
lng2=cells$x+L/2,
lat2=cells$y-L/2
)
return(corners)
}
## from (x,y) meters coordinates project to google map
change_projection_xy <- function(xy) {
colnames(xy) = c("x","y")
if(length(which(xy$y > 7300200 )) > 0) { xy$y[which(xy$y > 7300200)] = 7300100 }
if(length(which(xy$y < -7300200 )) > 0) { xy$y[which(xy$y < -7300200)] = -7300100 }
if(length(which(xy$x > 17084470 )) > 0) { xy$x[which(xy$x > 17084470)] = 17074470 }
if(length(which(xy$x < -17084470 )) > 0) { xy$x[which(xy$x < -17084470)] = -17074470 }
coordinates(xy) = c("x", "y")
proj4string(xy) = CRS("+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0")
xy = spTransform(xy,CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
xy_table=data.frame(x=as.double(xy@coords[,1]), y=as.double(xy@coords[,2]))
return(xy_table)
}
###############################################################################
# LOAD DATA
marine = read.table("donnees/figure_3a_underlying_data.tsv",header=T)
marineCorners=corners_of_square(data.frame(x=marine$x,y=marine$y),194000)
rect_1=change_projection_xy(data.frame(x=marineCorners$lng1,y=marineCorners$lat1))
rect_2=change_projection_xy(data.frame(x=marineCorners$lng2,y=marineCorners$lat2))
rect=cbind(rect_1,rect_2)
colnames(rect)=c("lng1","lat1","lng2","lat2")
marineRect=cbind(marine,rect)
colnames(marineRect)=c("x","y","mean_genetic_diversity", "temperature","regions","number_of_species","number_of_sequences", "lng1","lat1","lng2","lat2")
marineRect=marineRect[,c(3,4,6,7,8,9,10,11)]
freshwater=read.table("donnees/figure_3c_underlying_data.tsv",header=T)
freshwaterCorners=corners_of_square(data.frame(x=freshwater$x,y=freshwater$y),194000)
rect_1=change_projection_xy(data.frame(x=freshwaterCorners$lng1,y=freshwaterCorners$lat1))
rect_2=change_projection_xy(data.frame(x=freshwaterCorners$lng2,y=freshwaterCorners$lat2))
rect=cbind(rect_1,rect_2)
colnames(rect)=c("lng1","lat1","lng2","lat2")
freshwaterRect=cbind(freshwater,rect)
colnames(freshwaterRect)=c("x","y","mean_genetic_diversity","temperature", "regions","number_of_species","number_of_sequences","autocor","average_slope","lng1","lat1","lng2","lat2")
freshwaterRect=freshwaterRect[,c(3,4,6,7,10,11,12,13)]
cellsDat=rbind(marineRect,freshwaterRect)
watertype=c(rep("marine",dim(marineRect)[1]),rep("freshwater",dim(freshwaterRect)[1]))
cellsDat=cbind(cellsDat,watertype)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment