explore.processed.data.R 3.79 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## plots

fun.plot.hist.trait.per.set(data.all)

to.pdf(fun.hist.var.set(data.all,var='BATOT',cex=0.6),
       filename="figs/test.processed/fig.BATOT.set.pdf") 
to.pdf(fun.hist.var.set(data.all,var='G',cex=0.6),
       filename="figs/test.processed/fig.G.set.pdf") 
to.pdf(fun.hist.var.set(data.all,var='BA.G',cex=0.6),
       filename="figs/test.processed/fig.BA.G.set.pdf") 
to.pdf(fun.hist.var.set(data.all,var='D',cex=0.6),
       filename="figs/test.processed/fig.D.set.pdf") 
to.dev(fun.plot.xy.set(data.all,var.x='BATOT',var.y='BA.G',cex=0.6),dev=png,
       filename="figs/test.processed/fig.xy.BATOT.BA.G.set.png") 
to.dev(fun.plot.xy.set(data.all,var.x='D',var.y='BA.G',cex=0.6),dev=png,
       filename="figs/test.processed/fig.xy.D.BA.G.set.png") 
to.dev(fun.plot.xy.set(data.all,var.x='D',var.y='G',cex=0.6,col=col.vec[data.all$set]),dev=png,
       filename="figs/test.processed/fig.xy.D.G.set.png") 
to.dev(fun.plot.xy.set(data.all,var.x='BATOT',var.y='G',cex=0.6),dev=png,
       filename="figs/test.processed/fig.xy.BATOT.G.set.png") 


Georges Kunstler's avatar
Georges Kunstler committed
45
46
47
48
49
50
51
########
### 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

Georges Kunstler's avatar
Georges Kunstler committed
52
## remove outlier following Condit approach
Georges Kunstler's avatar
Georges Kunstler committed
53
data.all[['G']][!(trim.positive.growth(data.all[['G']]) &
Georges Kunstler's avatar
Georges Kunstler committed
54
55
trim.negative.growth(dbh1=data.all[['D']]*10,
                     dbh2=data.all[['D']]*10 +data.all[['year']]*data.all[['G']]))] <- NA
Georges Kunstler's avatar
Georges Kunstler committed
56
57

data.all[['BA.G']][!(trim.positive.growth(data.all[['G']]) &
Georges Kunstler's avatar
Georges Kunstler committed
58
59
trim.negative.growth(data.all[['D']]*10,dbh2=data.all[['D']]*10 +data.all[['year']]*data.all[['G']]))] <- NA

Georges Kunstler's avatar
Georges Kunstler committed
60
61
62
63
64

### 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
65
### NEED TO CHECK WHY JAPAN REACH 300 of BATOT 
66
par(mfrow=c(1,2))
Georges Kunstler's avatar
Georges Kunstler committed
67
plot(data.summarise$MAP,data.summarise$BATOT,
68
69
     ,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
70
legend("topright",legend=names(col.vec),col=col.vec,pch=1)
71
72
73
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
74
75
76
77
78
79
80
81
82

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,
83
      ,col=col.vec[data.summarise$set])
Georges Kunstler's avatar
Georges Kunstler committed
84
85
86
87
88
89
90
91
92
93
94
95
96


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)
97
qplot(data=data.summarise,x=set,y=BATOT,geom="boxplot",las=3)
Georges Kunstler's avatar
Georges Kunstler committed
98
99
100
ggplot(data.summarise[,], aes( x=n_sp, y=sd.Wood.density) ) +facet_wrap(~set)+
   geom_point(size=1 ) + geom_density2d()

101
102
103

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
104
105
106
107
108
109
110
111
112
113
114