explore.processed.data.R 5.34 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
########
### 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

31
32
33
## 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
34

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

Georges Kunstler's avatar
Georges Kunstler committed
39
40
pdf("figs/test.processed/boxplot.BATOT.D.G.BA.G.pdf")
par(mfrow=c(2,3))
41
boxplot(data.all$BATOT ~ data.all$set, las = 3)
Georges Kunstler's avatar
Georges Kunstler committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
boxplot(data.all$D ~ data.all$set, las = 3)
boxplot(data.all$G ~ data.all$set, las = 3)
boxplot(data.all$BA.G ~ data.all$set, las = 3)
dev.off()

pdf("figs/test.processed/boxplot.traits.pdf")
par(mfrow=c(2,3))
boxplot(data.all$Leaf.N.focal ~ data.all$set, las = 3,main="Leaf.N")
boxplot(data.all$SLA.focal ~ data.all$set, las = 3,main="SLA")
boxplot(data.all$Wood.density.focal ~ data.all$set, las = 3,main="Wood.density")
boxplot(data.all$Seed.mass.focal ~ data.all$set, las = 3,main="Seed.mass")
boxplot(data.all$Max.height.focal ~ data.all$set, las = 3,main="Max.height")
dev.off()


par(mfrow=c(2,2))
boxplot(data.all$Leaf.N.perc.species ~ data.all$set, las = 3,main="Leaf.N")
boxplot(data.all$SLA.perc.species ~ data.all$set, las = 3,main="SLA")
boxplot(data.all$Wood.density.perc.species ~ data.all$set, las = 3,main="Wood.density")
boxplot(data.all$Seed.mass.perc.species ~ data.all$set, las = 3,main="Seed.mass")

par(mfrow=c(2,2))
boxplot(data.all$Leaf.N.perc.genus ~ data.all$set, las = 3,main="Leaf.N")
boxplot(data.all$SLA.perc.genus ~ data.all$set, las = 3,main="SLA")
boxplot(data.all$Wood.density.perc.genus ~ data.all$set, las = 3,main="Wood.density")
boxplot(data.all$Seed.mass.perc.genus ~ data.all$set, las = 3,main="Seed.mass")

### compute percentage of evergreen and conif per plot



Georges Kunstler's avatar
Georges Kunstler committed
73
74
75
76
77

### 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
78
### NEED TO CHECK WHY JAPAN REACH 300 of BATOT
Georges Kunstler's avatar
Georges Kunstler committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

## angio
boxplot(data.summarise$per.angio~data.summarise$set,las=3)

per.angio.ecocode.mean <- tapply(data.summarise$per.angio,data.summarise$ecocode,mean,na.rm=TRUE)
per.angio.ecocode.quant <- do.call('rbind',tapply(data.summarise$per.angio,data.summarise$ecocode,quantile,
                                  probs=c(0.1,0.8),na.rm=TRUE))
names.ecocode <- tapply(data.summarise$ecocode,data.summarise$ecocode,unique)
names(per.angio.ecocode.mean) <- names.ecocode
par(mar=c(8.1,4.1,4.1,2.1))
mp <- barplot(per.angio.ecocode.mean,las=3)
segments(mp,per.angio.ecocode.quant[,1],
         mp,per.angio.ecocode.quant[,2])

## deciduous
boxplot(data.summarise$per.deciduous~data.summarise$set,las=3)

per.deciduous.ecocode.mean <- tapply(data.summarise$per.deciduous,data.summarise$ecocode,mean,na.rm=TRUE)
per.deciduous.ecocode.quant <- do.call('rbind',tapply(data.summarise$per.deciduous,data.summarise$ecocode,quantile,
                                  probs=c(0.1,0.8),na.rm=TRUE))
names.ecocode <- tapply(data.summarise$ecocode,data.summarise$ecocode,unique)
names(per.deciduous.ecocode.mean) <- names.ecocode
par(mar=c(8.1,4.1,4.1,2.1))
mp <- barplot(per.deciduous.ecocode.mean,las=3)
segments(mp,per.deciduous.ecocode.quant[,1],
         mp,per.deciduous.ecocode.quant[,2])






111
par(mfrow=c(1,2))
Georges Kunstler's avatar
Georges Kunstler committed
112
plot(data.summarise$MAP,data.summarise$BATOT,
113
114
     ,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
115
legend("topright",legend=names(col.vec),col=col.vec,pch=1)
116
117
plot(log(data.summarise$MAP),data.summarise$BATOT,
     ,col=col.vec[data.summarise$set],cex=0.1)
Georges Kunstler's avatar
Georges Kunstler committed
118
119
fun.boxplot.breaks(log(data.summarise$MAP),data.summarise$BATOT,
                   Nclass=15,add=TRUE)
Georges Kunstler's avatar
Georges Kunstler committed
120

Georges Kunstler's avatar
Georges Kunstler committed
121
122
by(data.summarise,INDICES=data.summarise$set,
   function(data,col.vec) {x11();plot(data$MAP,data$BATOT,
Georges Kunstler's avatar
Georges Kunstler committed
123
124
125
126
127
128
129
                      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,
130
      ,col=col.vec[data.summarise$set])
Georges Kunstler's avatar
Georges Kunstler committed
131
132
133
134
135
136
137
138
139
140
141
142
143


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

148
149
150

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
151
152
153
154
155
156
157
158
159
160
161