explore.processed.data.R 2.72 KB
Newer Older
Georges Kunstler's avatar
Georges Kunstler committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#######################################
#######################################
###### EXPLORE DATA SET BEFORE ANALYSIS
rm(list = ls())

source("R/process.data/process-fun.R")
source("R/process.data/test.tree.CWM-fun.R")
source("R/utils/plot.R")

filedir <- "output/processed"

mat.perc <- read.csv(file=file.path(filedir, "all.sites.perc.traits.csv"),
                     stringsAsFactors=FALSE)

### read all data
library(data.table)
system.time(data.all <-  fread(file.path(filedir, "data.all.csv"),
                     stringsAsFactors=FALSE))

if(dim(data.all)[1] != sum(mat.perc[['num.obs']]))
    stop('error not same dimension per ecoregion and total')

23

Georges Kunstler's avatar
Georges Kunstler committed
24
25
26
27
28
29
30
31
########
### TODO
#- look at BATOT ALONG MAP AND MAT (log scale)
#- how to compute FD on plot with diferent size
#- pattern of CWM
#- pattern ED angio/conif


32
33
34
## look at BATOT per ecocode
MAP.ECOCODE <- tapply(data.all$MAP,INDEX=data.all$ecocode,FUN=mean)
SET.ECOCODE <- tapply(data.all$set,INDEX=data.all$ecocode,FUN=unique)
Georges Kunstler's avatar
Georges Kunstler committed
35

36
37
38
39
40
boxplot(data.all$BATOT ~ data.all$ecocode, las = 3,
        at = log(MAP.ECOCODE), boxwex = 0.05, outline = FALSE,
        col=col.vec[SET.ECOCODE])

boxplot(data.all$BATOT ~ data.all$set, las = 3)
Georges Kunstler's avatar
Georges Kunstler committed
41
42
43
44
45

### compute mean BATOT, number of species, traits and VAR OF TRAITS per cluster

system.time(data.summarise <- fun.compute.all.var.cluster(data.all))

Georges Kunstler's avatar
Georges Kunstler committed
46
### NEED TO CHECK WHY JAPAN REACH 300 of BATOT
47
par(mfrow=c(1,2))
Georges Kunstler's avatar
Georges Kunstler committed
48
plot(data.summarise$MAP,data.summarise$BATOT,
49
50
     ,col=col.vec[data.summarise$set],cex=0.1)
fun.boxplot.breaks((data.summarise$MAP),data.summarise$BATOT,Nclass=15,add=TRUE)
Georges Kunstler's avatar
Georges Kunstler committed
51
legend("topright",legend=names(col.vec),col=col.vec,pch=1)
52
53
54
plot(log(data.summarise$MAP),data.summarise$BATOT,
     ,col=col.vec[data.summarise$set],cex=0.1)
fun.boxplot.breaks(log(data.summarise$MAP),data.summarise$BATOT,Nclass=15,add=TRUE)
Georges Kunstler's avatar
Georges Kunstler committed
55
56
57
58
59
60
61
62
63

by(data.summarise,INDICES=data.summarise$set,function(data,col.vec) {x11();plot(data$MAP,data$BATOT,
                      main=unique(data$set),
                      col=col.vec[data$set])},col.vec)

plot(data.summarise$MAP,data.summarise$sd.SLA,
     ,col=col.vec[data.summarise$set])

plot(data.summarise$MAP,data.summarise$mean.SLA,
64
      ,col=col.vec[data.summarise$set])
Georges Kunstler's avatar
Georges Kunstler committed
65
66
67
68
69
70
71
72
73
74
75
76
77


pch.vec <- 1:14
names(pch.vec) <- names(col.vec)
plot(data.summarise$n_sp,data.summarise$sd.Wood.density,
     ,col=col.vec[data.summarise$set],pch=pch.vec[data.summarise$set])
legend("topright",legend=names(col.vec),col=col.vec,pch=pch.vec)




#
library(ggplot2)
78
qplot(data=data.summarise,x=set,y=BATOT,geom="boxplot",las=3)
Georges Kunstler's avatar
Georges Kunstler committed
79
80
81
ggplot(data.summarise[,], aes( x=n_sp, y=sd.Wood.density) ) +facet_wrap(~set)+
   geom_point(size=1 ) + geom_density2d()

82
83
84

ggplot(data.all[,], aes( x=BATOT, y=Wood.density.CWM.fill) ) +facet_wrap(~set)+
   geom_point(size=1 ) + geom_density2d()
Georges Kunstler's avatar
Georges Kunstler committed
85
86
87
88
89
90
91
92
93
94
95