Skip to content

Commit e59a4dd

Browse files
committed
two period comparison boxplot biome specific patterns on P only
1 parent 8c1744f commit e59a4dd

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

R/Two_period_comparison_script.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ dev.off()
9999
# biome-specific comparisons
100100
pdf(paste0(analysesDir, "/two_period_biome_comparisons.pdf"),
101101
width = 10, height = 8)
102-
two_period_biome_diff()
102+
two_period_biome_diff_P()
103103
dev.off()
104104

105105
# spatial comparison of predictability only
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
####################################################################################
3+
two_period_biome_diff_P <- function() {
4+
5+
### read in all the data (two periods temperature and precipitation)
6+
temp_p1 <- read.csv(paste0(dataDir, "/temp_PCM_1901_1990.csv"))
7+
temp_p2 <- read.csv(paste0(dataDir, "/temp_PCM_1991_2012.csv"))
8+
prec_p1 <- read.csv(paste0(dataDir, "/pre_PCM_1901_1990.csv"))
9+
prec_p2 <- read.csv(paste0(dataDir, "/pre_PCM_1991_2012.csv"))
10+
11+
### read in biome coordinates
12+
corFile=read.csv(paste0(corDir, "/CRU_Biome.csv"))
13+
14+
### assign biomes
15+
temp_p1$biome <- corFile$BIOME
16+
temp_p2$biome <- corFile$BIOME
17+
prec_p1$biome <- corFile$BIOME
18+
prec_p2$biome <- corFile$BIOME
19+
20+
### assign period indication
21+
temp_p1$period <- "1st"
22+
temp_p2$period <- "2nd"
23+
prec_p1$period <- "1st"
24+
prec_p2$period <- "2nd"
25+
26+
# prepare dataframe
27+
temp_p1<- subset(temp_p1, biome > 0)
28+
temp_p2<- subset(temp_p2, biome > 0)
29+
prec_p1<- subset(prec_p1, biome > 0)
30+
prec_p2<- subset(prec_p2, biome > 0)
31+
32+
temp_p1 <- subset(temp_p1, biome < 98)
33+
temp_p2 <- subset(temp_p2, biome < 98)
34+
prec_p1 <- subset(prec_p1, biome < 98)
35+
prec_p2 <- subset(prec_p2, biome < 98)
36+
37+
### create long dfs
38+
temp_long <- as.data.frame(rbind(cbind(temp_p1$biome, temp_p1$period, temp_p1$P, temp_p1$C, temp_p1$M),
39+
cbind(temp_p2$biome, temp_p2$period, temp_p2$P, temp_p2$C, temp_p2$M)))
40+
colnames(temp_long) <- c("biome", "period", "predictability", "constancy", "contingency")
41+
temp_long$predictability <- as.numeric(as.character(temp_long$predictability))
42+
temp_long$constancy <- as.numeric(as.character(temp_long$constancy))
43+
temp_long$contingency <- as.numeric(as.character(temp_long$contingency))
44+
45+
46+
prec_long <- as.data.frame(rbind(cbind(prec_p1$biome, prec_p1$period, prec_p1$P, prec_p1$C, prec_p1$M),
47+
cbind(prec_p2$biome, prec_p2$period, prec_p2$P, prec_p2$C, prec_p2$M)))
48+
colnames(prec_long) <- c("biome", "period", "predictability", "constancy", "contingency")
49+
prec_long$predictability <- as.numeric(as.character(prec_long$predictability))
50+
prec_long$constancy <- as.numeric(as.character(prec_long$constancy))
51+
prec_long$contingency <- as.numeric(as.character(prec_long$contingency))
52+
53+
54+
par(mfrow=c(2,1),pxd=T)
55+
56+
## Plotting
57+
boxplot(predictability ~ period*biome, data=temp_long, notch=TRUE,
58+
col=(c("gold","darkgreen")), ylim=c(0,1),
59+
names=c(1,NA,2,NA,3,NA,4,NA,5,NA,6,NA,7,NA,8,NA,9,NA,10,NA,11,NA,
60+
12,NA,13,NA,14,NA),
61+
#main="Biome-specific temperature P comparison of the two periods",
62+
xlab="Biome", ylab="Temperature predictability")
63+
legend('bottomright', c("1901-1990", "1991-2012"), fill=c("gold", "darkgreen"))
64+
65+
boxplot(predictability ~ period*biome, data=prec_long, notch=TRUE,
66+
col=(c("gold","darkgreen")), ylim=c(0,1),
67+
names=c(1,NA,2,NA,3,NA,4,NA,5,NA,6,NA,7,NA,8,NA,9,NA,10,NA,11,NA,
68+
12,NA,13,NA,14,NA),
69+
#main="Biome-specific precipitation P comparison of the two periods",
70+
xlab="Biome", ylab="Precipitation predictability")
71+
legend('bottomright', c("1901-1990", "1991-2012"), fill=c("gold", "darkgreen"))
72+
73+
74+
}

0 commit comments

Comments
 (0)