Load data

Load all experiment output files in the “yield” folder, generated with this version (“Simple crop model with spatial diversity”).

file_names <- paste0("yield/", list.files("yield"))

isThisVersion <- grepl("SIMPLE-crop-model_withSpatialDiversity_yield", file_names)

yieldData <- do.call(rbind, lapply(file_names[isThisVersion], read.csv))

Preview the data structure

knitr::kable(head(yieldData))
randomSeed temperature_annualMaxAt2m temperature_annualMinAt2m temperature_meanDailyFluctuation temperature_dailyLowerDeviation temperature_dailyUpperDeviation solar_annualMax solar_annualMin solar_meanDailyFluctuation CO2_annualMin CO2_annualMax CO2_meanDailyFluctuation precipitation_yearlyMean precipitation_yearlySd precipitation_dailyCum_nSamples precipitation_dailyCum_maxSampleSize precipitation_dailyCum_plateauValue_yearlyMean precipitation_dailyCum_plateauValue_yearlySd precipitation_dailyCum_inflection1_yearlyMean precipitation_dailyCum_inflection1_yearlySd precipitation_dailyCum_rate1_yearlyMean precipitation_dailyCum_rate1_yearlySd precipitation_dailyCum_inflection2_yearlyMean precipitation_dailyCum_inflection2_yearlySd precipitation_dailyCum_rate2_yearlyMean precipitation_dailyCum_rate2_yearlySd currentYear currentDayOfYear precipitation_yearTotal meanARID x y elevation DC z CN FC WHC albedo crop T_sum HI I_50A I_50B T_base T_opt RUE I_50maxH I_50maxW T_heat T_extreme S_CO2 S_water sowingDay harvestDay meanARID_grow yield
0 37 12.8 2.2 6.8 7.9 24.2 9.2 3.3 245 255 1 639.0508 142.2 200 10 0.6291136 0.1 40 5 0.07 0.02 240 20 0.08 0.02 0 365 650.9614 0.7177885 0 49 203 0.4555547 374 50 0.1643240 0.1043240 0.3025948 ‘dry bean’ 2700 0.40 450 600 5 27 0.80 90 20 32 45 0.07 0.9 166 266 0.7872982 140.7735
0 37 12.8 2.2 6.8 7.9 24.2 9.2 3.3 245 255 1 639.0508 142.2 200 10 0.6291136 0.1 40 5 0.07 0.02 240 20 0.08 0.02 0 365 650.9614 0.4924062 1 49 195 0.4198016 1700 50 0.2475175 0.1875175 0.4440183 ‘soybean 1’ 2500 0.35 680 300 6 27 0.86 120 20 36 50 0.07 0.9 150 300 0.7419127 194.6076
0 37 12.8 2.2 6.8 7.9 24.2 9.2 3.3 245 255 1 639.0508 142.2 200 10 0.6291136 0.1 40 5 0.07 0.02 240 20 0.08 0.02 0 365 650.9614 0.6217397 2 49 202 0.3549441 1543 50 0.1607935 0.1007935 0.2108166 ‘soybean 1’ 2500 0.35 680 300 6 27 0.86 120 20 36 50 0.07 0.9 150 300 0.8070835 176.3353
0 37 12.8 2.2 6.8 7.9 24.2 9.2 3.3 245 255 1 639.0508 142.2 200 10 0.6291136 0.1 40 5 0.07 0.02 240 20 0.08 0.02 0 365 650.9614 0.7405726 3 49 195 0.4435491 387 50 0.1637345 0.1037345 0.1288946 ‘cassava’ 5400 0.65 650 300 12 28 1.10 100 15 38 50 0.07 1.0 76 167 0.8441933 0.0000
0 37 12.8 2.2 6.8 7.9 24.2 9.2 3.3 245 255 1 639.0508 142.2 200 10 0.6291136 0.1 40 5 0.07 0.02 240 20 0.08 0.02 0 365 650.9614 0.5051434 4 49 179 0.3716983 1457 50 0.2471591 0.1871591 0.4758708 ‘potato 6’ 2500 0.90 480 400 4 22 1.30 50 30 34 45 0.10 0.4 120 270 0.6501603 1600.9021
0 37 12.8 2.2 6.8 7.9 24.2 9.2 3.3 245 255 1 639.0508 142.2 200 10 0.6291136 0.1 40 5 0.07 0.02 240 20 0.08 0.02 0 365 650.9614 0.5974389 5 49 213 0.4531982 1170 50 0.2115057 0.1515057 0.2976785 ‘peanut’ 3100 0.35 520 550 10 28 1.20 100 5 36 50 0.07 2.0 150 270 0.7785013 0.0000

All crops

Visualise simulation results for all crops included in Zhao et al. 2019 (except those taking more than a year to reach maturity; i.e. banana, cotton, peanut and cassava). NOTE: banana is already not used for simulations.

Preparations

Reconstruct cropTable content:

cropTableNames <- c("crop", "T_sum", "HI", "I_50A", "I_50B", "T_base", "T_opt", "RUE", "I_50maxH", "I_50maxW", "T_heat", "T_extreme", "S_CO2", "S_water", "sowingDay", "harvestDay")

cropTable <- data.frame(matrix(ncol=length(cropTableNames),nrow=0, dimnames=list(NULL, cropTableNames)))

for (aCrop in levels(yieldData$crop))
{
  cropTable <- rbind(cropTable, yieldData[match(aCrop, yieldData$crop), cropTableNames])
}

Filter out cassava, cotton and peanut:

notAnnualCrops <- c(" 'cassava'", " 'cotton'", " 'peanut'")
notAnnual <- yieldData$crop == " 'cassava'" | yieldData$crop == " 'cotton'" | yieldData$crop == " 'peanut'"

yieldData <- yieldData[!notAnnual,]

# crop factor variable needs resetting levels
yieldData$crop <- factor(yieldData$crop)

Get vector of colours to represent crops:

cropColours <- rainbow(nlevels(yieldData$crop), s = 0.8, end = 0.9)

Precalculate ranges of ARID and yield:

minARID = round(min(c(yieldData$meanARID, yieldData$meanARID_grow), na.rm = TRUE), digits = 2)
maxARID = round(max(c(yieldData$meanARID, yieldData$meanARID_grow), na.rm = TRUE), digits = 2)

minYield = round(min(yieldData$yield), digits = -1)
maxYield = round(max(yieldData$yield), digits = -1)

minElevation = round(min(yieldData$elevation, na.rm = TRUE), digits = -1)
maxElevation = round(max(yieldData$elevation, na.rm = TRUE), digits = -1)

minDC = round(min(yieldData$DC, na.rm = TRUE), digits = 2)
maxDC = round(max(yieldData$DC, na.rm = TRUE), digits = 2)

minWHC = round(min(yieldData$WHC, na.rm = TRUE), digits = 2)
maxWHC = round(max(yieldData$WHC, na.rm = TRUE), digits = 2)

minAlbedo = round(min(yieldData$albedo, na.rm = TRUE), digits = 2)
maxAlbedo = round(max(yieldData$albedo, na.rm = TRUE), digits = 2)

Summary statistics per crop

yieldData_summary <- tapply(as.numeric(as.character(yieldData$yield)), yieldData$crop, summary)

yieldData_summary <- data.frame(Reduce(rbind, yieldData_summary), row.names = names(yieldData_summary))
knitr::kable(yieldData_summary)
Min. X1st.Qu. Median Mean X3rd.Qu. Max.
‘carrot’ 0.00000 0.0000000 0.00000 0.00000 0.0000 0.0000
‘dry bean’ 39.77323 99.7875152 138.04051 142.10117 179.2089 319.9080
‘greenbean’ 265.14017 321.6465355 343.35884 343.65089 362.6656 451.7595
‘maize’ 0.00000 107.2547509 246.12363 287.56321 427.5556 1408.1039
‘potato 1’ 1166.78468 1310.1273733 1386.73555 1387.55447 1447.1874 1784.9024
‘potato 2’ 1027.97392 1165.6330248 1236.60241 1237.03806 1292.9409 1590.2670
‘potato 3’ 580.03798 655.1878508 695.09275 695.43542 726.8206 898.7303
‘potato 4’ 575.42161 655.4905521 695.38885 695.55159 726.6423 899.8745
‘potato 5’ 1228.84560 1387.5865958 1469.55606 1469.77962 1532.8896 1891.2553
‘potato 6’ 1247.26154 1394.7612322 1477.37943 1477.57982 1539.7144 1897.5005
‘rice’ 0.00000 145.2532419 209.46807 222.27540 291.1395 564.4086
‘soybean 1’ 73.11294 149.8101776 193.91008 196.23320 238.4853 387.3273
‘soybean 2’ 85.50341 174.2560419 223.87381 226.78671 274.1501 451.4391
‘sweetcorn’ 0.00000 7.0465511 55.56285 101.11178 157.1649 793.8814
‘tomato 1’ 0.00000 1.2891238 39.27599 96.40991 148.8108 900.7742
‘tomato 2’ 0.00000 0.9301013 30.41383 70.97555 110.9608 566.9059
‘wheat 1’ 0.00000 316.5471492 387.40010 326.30991 449.1688 512.2972
‘wheat 2’ 0.00000 330.6847933 401.76636 335.06729 457.5385 535.4905
plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/yieldPerCrop.png"

grScale = 2
fontRescale = 0
fontRescaleDay = 0

png(plotName, width = grScale * 500, height = grScale * 300)

par(mar = c(6,5,1,1))

boxplot(yield ~ factor(crop), data = yieldData,#[yieldData$yield > 0,], # show only non-zero yield 
        ylab = expression(paste("yield (", g/m^2, ")")), xlab = "",
        las = 2, 
        col = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Effect of elevation on ARID

Plotting ARID vs elevation:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsElevation.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minElevation, maxElevation),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$elevation[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ elevation, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minElevation, maxElevation),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$elevation[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ elevation, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minElevation, maxElevation), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minElevation, maxElevation, by = 5),
     tck = 0, lwd = 0)

mtext("elevation (m)", side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[!cropTable$crop %in% notAnnualCrops], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$elevation[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ elevation, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘carrot’ 0.0049835 0.8607058 0 0.0000421 0.3887741 -0.0000086
‘dry bean’ 0.0097498 0.7170729 0 0.0001147 0.0955980 0.0000608
‘greenbean’ 0.0022418 0.7562050 0 0.0000253 0.6974299 -0.0000282
‘maize’ 0.0081007 0.7714857 0 0.0000707 0.1681543 0.0000311
‘potato 1’ -0.0069193 0.8064059 0 -0.0000620 0.2310611 0.0000145
‘potato 2’ -0.0021134 0.7956317 0 -0.0000186 0.7167364 -0.0000295
‘potato 3’ -0.0047963 0.8016456 0 -0.0000427 0.4078650 -0.0000106
‘potato 4’ 0.0119952 0.7714019 0 0.0001065 0.0376010 0.0001106
‘potato 5’ 0.0019947 0.7892364 0 0.0000176 0.7310610 -0.0000297
‘potato 6’ -0.0048793 0.8005776 0 -0.0000436 0.3992844 -0.0000097
‘rice’ -0.0049897 0.7164653 0 -0.0000663 0.3857734 -0.0000082
‘soybean 1’ 0.0296227 0.6805204 0 0.0003173 0.0000003 0.0008445
‘soybean 2’ 0.0120087 0.7198775 0 0.0001266 0.0368998 0.0001111
‘sweetcorn’ 0.0065119 0.7705374 0 0.0000587 0.2622967 0.0000087
‘tomato 1’ 0.0030934 0.7869185 0 0.0000278 0.5955884 -0.0000244
‘tomato 2’ 0.0139102 0.7670206 0 0.0001251 0.0173492 0.0001593
‘wheat 1’ -0.0080609 0.5373838 0 -0.0001210 0.2146372 0.0000228
‘wheat 2’ 0.0037392 0.4969948 0 0.0000563 0.5654026 -0.0000283

Effect of drainage coefficient (DC) on ARID

Plotting ARID vs DC:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsDC.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minDC, maxDC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$DC[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ DC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minDC, maxDC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$DC[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ DC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minDC, maxDC), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minDC, maxDC, by = 0.05),
     tck = 0, lwd = 0)

mtext(expression("drainage coefficient " (m^3*m^-3) ), side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[!cropTable$crop %in% notAnnualCrops], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$DC[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ DC, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘carrot’ 0.0085272 0.8648620 0 0.0085558 0.1402929 0.0000393
‘dry bean’ 0.0129196 0.7307964 0 0.0183970 0.0272128 0.0001327
‘greenbean’ 0.0213209 0.7466868 0 0.0291114 0.0002172 0.0004214
‘maize’ 0.0206320 0.7746034 0 0.0219447 0.0004474 0.0003911
‘potato 1’ 0.0081320 0.7895963 0 0.0088398 0.1592707 0.0000328
‘potato 2’ 0.0115471 0.7857213 0 0.0124926 0.0474314 0.0000994
‘potato 3’ 0.0072290 0.7892192 0 0.0077899 0.2122261 0.0000187
‘potato 4’ 0.0198017 0.7819322 0 0.0215365 0.0005980 0.0003588
‘potato 5’ 0.0124353 0.7860760 0 0.0134442 0.0321230 0.0001210
‘potato 6’ 0.0105233 0.7861454 0 0.0114433 0.0690728 0.0000772
‘rice’ 0.0042297 0.6997952 0 0.0068344 0.4622206 -0.0000152
‘soybean 1’ 0.0251375 0.7277545 0 0.0326787 0.0000121 0.0005989
‘soybean 2’ 0.0117399 0.7376653 0 0.0150874 0.0413335 0.0001047
‘sweetcorn’ 0.0215731 0.7704988 0 0.0236090 0.0002040 0.0004317
‘tomato 1’ 0.0126074 0.7855732 0 0.0138008 0.0305265 0.0001250
‘tomato 2’ 0.0138291 0.7844687 0 0.0151349 0.0180128 0.0001571
‘wheat 1’ 0.0227284 0.4918145 0 0.0426985 0.0004665 0.0004744
‘wheat 2’ 0.0111673 0.4980329 0 0.0203837 0.0860111 0.0000824

Effect of water holding capacity (WHC) on ARID

Plotting ARID vs DC:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsWHC.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minWHC, maxWHC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$WHC[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ WHC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minWHC, maxWHC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$WHC[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ WHC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minWHC, maxWHC), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minWHC, maxWHC, by = 0.05),
     tck = 0, lwd = 0)

mtext(expression("water holding capacity " (m^3*m^-3) ), side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[!cropTable$crop %in% notAnnualCrops], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$WHC[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ WHC, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘carrot’ -0.0576890 0.8864454 0 -0.1154394 0 0.0032947
‘dry bean’ -0.1037187 0.7840343 0 -0.2926888 0 0.0107237
‘greenbean’ -0.0942897 0.8001210 0 -0.2578982 0 0.0088576
‘maize’ -0.1828022 0.8449242 0 -0.3963862 0 0.0333832
‘potato 1’ -0.1454126 0.8410631 0 -0.3153012 0 0.0211121
‘potato 2’ -0.1445993 0.8391066 0 -0.3134622 0 0.0208757
‘potato 3’ -0.1378907 0.8382170 0 -0.3014857 0 0.0189809
‘potato 4’ -0.1330049 0.8361165 0 -0.2885244 0 0.0176576
‘potato 5’ -0.1405683 0.8384958 0 -0.3037926 0 0.0197264
‘potato 6’ -0.1324367 0.8358376 0 -0.2926591 0 0.0175065
‘rice’ -0.1129910 0.7575460 0 -0.3637312 0 0.0127343
‘soybean 1’ -0.0908206 0.7799233 0 -0.2385932 0 0.0082156
‘soybean 2’ -0.1024567 0.7851518 0 -0.2648926 0 0.0104646
‘sweetcorn’ -0.1823406 0.8418128 0 -0.3975383 0 0.0332155
‘tomato 1’ -0.1300717 0.8355266 0 -0.2855089 0 0.0168852
‘tomato 2’ -0.1437920 0.8394390 0 -0.3148545 0 0.0206427
‘wheat 1’ -0.1163702 0.5787369 0 -0.4342302 0 0.0135004
‘wheat 2’ -0.1153035 0.5710012 0 -0.4228244 0 0.0132531

Effect of albedo on ARID

Plotting ARID vs DC:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsAlbedo.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minAlbedo, maxAlbedo),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$albedo[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ albedo, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minAlbedo, maxAlbedo),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$albedo[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ albedo, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minAlbedo, maxAlbedo), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minAlbedo, maxAlbedo, by = 0.05),
     tck = 0, lwd = 0)

mtext("albedo", side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[!cropTable$crop %in% notAnnualCrops], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$albedo[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ albedo, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘carrot’ -0.1394156 0.9113675 0 -0.1406134 0 0.0194039
‘dry bean’ -0.1533635 0.8070650 0 -0.2220470 0 0.0234870
‘greenbean’ -0.1534263 0.8243587 0 -0.2098861 0 0.0235072
‘maize’ -0.2173864 0.8562218 0 -0.2364523 0 0.0472239
‘potato 1’ -0.1937691 0.8568417 0 -0.2102446 0 0.0375143
‘potato 2’ -0.1832874 0.8515313 0 -0.1984297 0 0.0335615
‘potato 3’ -0.2011412 0.8585232 0 -0.2184499 0 0.0404256
‘potato 4’ -0.1878640 0.8533862 0 -0.2018834 0 0.0352608
‘potato 5’ -0.1919027 0.8548748 0 -0.2083332 0 0.0367942
‘potato 6’ -0.1944388 0.8556290 0 -0.2133293 0 0.0377742
‘rice’ -0.1513211 0.7760113 0 -0.2423391 0 0.0228657
‘soybean 1’ -0.1709813 0.8104874 0 -0.2234458 0 0.0292025
‘soybean 2’ -0.1542931 0.8048571 0 -0.1985701 0 0.0237740
‘sweetcorn’ -0.1937742 0.8453601 0 -0.2126112 0 0.0375160
‘tomato 1’ -0.1837140 0.8534802 0 -0.2015969 0 0.0337180
‘tomato 2’ -0.1953541 0.8563878 0 -0.2135475 0 0.0381304
‘wheat 1’ -0.1220623 0.5820608 0 -0.2289755 0 0.0148576
‘wheat 2’ -0.1250768 0.5777173 0 -0.2304428 0 0.0156026

Effect of albedo on yield

Plotting ARID vs DC:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/yieldvsAlbedo.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2), nrow = 1, ncol = 2), widths = c(10, 3))

par(mar = c(5,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minAlbedo, maxAlbedo),
     c(minYield, maxYield),
     xlab = "albedo",
     ylab = "yield")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$albedo[yieldData$crop == aCrop],
         yieldData$yield[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(yield ~ albedo, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[!cropTable$crop %in% notAnnualCrops], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$albedo[yieldData$crop == aCrop], y = yieldData$yield[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(yield ~ albedo, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
## Warning in cor(x = yieldData$albedo[yieldData$crop == aCrop], y =
## yieldData$yield[yieldData$crop == : the standard deviation is zero
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘carrot’ NA 0.00000 NaN 0.00000 NaN NaN
‘dry bean’ 0.1359339 122.09630 0 66.25213 0e+00 0.0184444
‘greenbean’ 0.0703688 338.03348 0 18.68530 0e+00 0.0049187
‘maize’ 0.1741384 185.93152 0 340.29877 0e+00 0.0302907
‘potato 1’ 0.0708961 1369.69938 0 59.76041 0e+00 0.0049930
‘potato 2’ 0.0668159 1221.21330 0 52.68106 0e+00 0.0044306
‘potato 3’ 0.0766446 685.19785 0 34.18819 0e+00 0.0058410
‘potato 4’ 0.0731333 685.89216 0 32.12413 0e+00 0.0053154
‘potato 5’ 0.0905043 1445.58891 0 81.14264 0e+00 0.0081576
‘potato 6’ 0.0791195 1456.11952 0 71.80400 0e+00 0.0062266
‘rice’ 0.1356812 182.95955 0 130.89453 0e+00 0.0183769
‘soybean 1’ 0.1614937 170.94024 0 85.03703 0e+00 0.0260481
‘soybean 2’ 0.1420369 201.33593 0 84.73250 0e+00 0.0201420
‘sweetcorn’ 0.1511939 55.11097 0 155.05472 0e+00 0.0228266
‘tomato 1’ 0.1606683 43.06304 0 176.30359 0e+00 0.0257812
‘tomato 2’ 0.1713031 30.02538 0 135.91893 0e+00 0.0293116
‘wheat 1’ 0.0300694 312.89416 0 44.60619 2e-07 0.0008704
‘wheat 2’ 0.0292444 321.80157 0 44.00976 5e-07 0.0008214

Wheat vs rice

Preparations

Create filter for wheat and rice:

wheatAndRice <- c(" 'wheat 1'", " 'wheat 2'", " 'rice'")

isWheatAndRice <- yieldData$crop == " 'wheat 1'" | yieldData$crop == " 'wheat 2'" | yieldData$crop == " 'rice'"

Apply filter:

yieldData <- yieldData[isWheatAndRice,]

# crop factor variable needs resetting levels
yieldData$crop <- factor(yieldData$crop)

Get vector of colours to represent crops:

cropColours <- rainbow(nlevels(yieldData$crop), s = 0.8, end = 0.9)

Precalculate ranges of ARID and yield:

minARID = round(min(c(yieldData$meanARID, yieldData$meanARID_grow), na.rm = TRUE), digits = 2)
maxARID = round(max(c(yieldData$meanARID, yieldData$meanARID_grow), na.rm = TRUE), digits = 2)

minYield = round(min(yieldData$yield), digits = -1)
maxYield = round(max(yieldData$yield), digits = -1)

minElevation = round(min(yieldData$elevation, na.rm = TRUE), digits = -1)
maxElevation = round(max(yieldData$elevation, na.rm = TRUE), digits = -1)

minDC = round(min(yieldData$DC, na.rm = TRUE), digits = 2)
maxDC = round(max(yieldData$DC, na.rm = TRUE), digits = 2)

minWHC = round(min(yieldData$WHC, na.rm = TRUE), digits = 2)
maxWHC = round(max(yieldData$WHC, na.rm = TRUE), digits = 2)

minAlbedo = round(min(yieldData$albedo, na.rm = TRUE), digits = 2)
maxAlbedo = round(max(yieldData$albedo, na.rm = TRUE), digits = 2)

Summary statistics per crop

yieldData_summary <- tapply(as.numeric(as.character(yieldData$yield)), yieldData$crop, summary)

yieldData_summary <- data.frame(Reduce(rbind, yieldData_summary), row.names = names(yieldData_summary))
knitr::kable(yieldData_summary)
Min. X1st.Qu. Median Mean X3rd.Qu. Max.
‘rice’ 0 145.2532 209.4681 222.2754 291.1395 564.4086
‘wheat 1’ 0 316.5471 387.4001 326.3099 449.1688 512.2972
‘wheat 2’ 0 330.6848 401.7664 335.0673 457.5385 535.4905
plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/yieldPerCrop_wheatVsRice.png"

grScale = 2
fontRescale = 0
fontRescaleDay = 0

png(plotName, width = grScale * 500, height = grScale * 300)

par(mar = c(6,5,1,1))

boxplot(yield ~ factor(crop), data = yieldData,#[yieldData$yield > 0,], # show only non-zero yield 
        ylab = expression(paste("yield (", g/m^2, ")")), xlab = "",
        las = 2, 
        col = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Effect of elevation on ARID

Plotting ARID vs elevation:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsElevation_wheatVsRice.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minElevation, maxElevation),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$elevation[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ elevation, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minElevation, maxElevation),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$elevation[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ elevation, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minElevation, maxElevation), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minElevation, maxElevation, by = 5),
     tck = 0, lwd = 0)

mtext("elevation (m)", side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[cropTable$crop %in% wheatAndRice], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$elevation[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ elevation, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘rice’ -0.0049897 0.7164653 0 -6.63e-05 0.3857734 -8.20e-06
‘wheat 1’ -0.0080609 0.5373838 0 -1.21e-04 0.2146372 2.28e-05
‘wheat 2’ 0.0037392 0.4969948 0 5.63e-05 0.5654026 -2.83e-05

Effect of drainage coefficient (DC) on ARID

Plotting ARID vs drainage coefficient:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsDC_wheatVsRice.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minDC, maxDC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$DC[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ DC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minDC, maxDC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$DC[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ DC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minDC, maxDC), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minDC, maxDC, by = 0.05),
     tck = 0, lwd = 0)

mtext(expression("drainage coefficient " (m^3*m^-3) ), side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[cropTable$crop %in% wheatAndRice], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$DC[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ DC, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘rice’ 0.0042297 0.6997952 0 0.0068344 0.4622206 -0.0000152
‘wheat 1’ 0.0227284 0.4918145 0 0.0426985 0.0004665 0.0004744
‘wheat 2’ 0.0111673 0.4980329 0 0.0203837 0.0860111 0.0000824

Effect of water holding capacity (WHC) on ARID

Plotting ARID vs water holding capacity:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsWHC_wheatVsRice.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minWHC, maxWHC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$WHC[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ WHC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minWHC, maxWHC),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$WHC[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ WHC, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minWHC, maxWHC), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minWHC, maxWHC, by = 0.05),
     tck = 0, lwd = 0)

mtext(expression("water holding capacity " (m^3*m^-3) ), side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[cropTable$crop %in% wheatAndRice], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$WHC[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ WHC, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘rice’ -0.1129910 0.7575460 0 -0.3637312 0 0.0127343
‘wheat 1’ -0.1163702 0.5787369 0 -0.4342302 0 0.0135004
‘wheat 2’ -0.1153035 0.5710012 0 -0.4228244 0 0.0132531

Effect of albedo on ARID

Plotting ARID vs albedo:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/ARIDvsAlbedo_wheatVsRice.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2, 3, 4, 4, 4), nrow = 3, ncol = 2),
       heights = c(10, 10, 2), widths = c(10, 3))

par(mar = c(1,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minAlbedo, maxAlbedo),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (current year)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$albedo[yieldData$crop == aCrop],
         yieldData$meanARID[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID ~ albedo, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

plot(c(minAlbedo, maxAlbedo),
     c(minARID, maxARID),
     xaxt ='n',
     xlab = "",
     ylab = "mean ARID (grow seasons)")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$albedo[yieldData$crop == aCrop],
         yieldData$meanARID_grow[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(meanARID_grow ~ albedo, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(1, 1, 1, 0.1))

plot(c(minAlbedo, maxAlbedo), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

axis(3, 
     at = seq(minAlbedo, maxAlbedo, by = 0.05),
     tck = 0, lwd = 0)

mtext("albedo", side = 1, line = -2)

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[cropTable$crop %in% wheatAndRice], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$albedo[yieldData$crop == aCrop], y = yieldData$meanARID_grow[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(meanARID_grow ~ albedo, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘rice’ -0.1513211 0.7760113 0 -0.2423391 0 0.0228657
‘wheat 1’ -0.1220623 0.5820608 0 -0.2289755 0 0.0148576
‘wheat 2’ -0.1250768 0.5777173 0 -0.2304428 0 0.0156026

Effect of albedo on yield

Plotting yield vs albedo:

plotName = "plots/SIMPLE-crop-model_withSpatialDiversity/yieldvsAlbedo_wheatVsRice.png"

grScale = 2
fontRescale = 0.5

png(plotName, width = grScale * 500, height = grScale * 300)

layout(matrix(c(1, 2), nrow = 1, ncol = 2), widths = c(10, 3))

par(mar = c(5,5,1,1), cex.lab = 0.8 * grScale)

plot(c(minAlbedo, maxAlbedo),
     c(minYield, maxYield),
     xlab = "albedo",
     ylab = "yield")

for (aCrop in levels(yieldData$crop))
{
  points(yieldData$albedo[yieldData$crop == aCrop],
         yieldData$yield[yieldData$crop == aCrop],
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         pch = 20
  )
  abline(lm(yield ~ albedo, data = yieldData[yieldData$crop == aCrop,]),
         col = cropColours[match(aCrop, levels(yieldData$crop))],
         lwd = 2)
}

par(mar = c(0, 0, 0, 0), cex = 0.8 * grScale)

plot(c(0, 1), c(0, 1), ann = F, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n')

legend(x = 0, y = 1, 
       legend = stringi::stri_c(cropTable$S_water[cropTable$crop %in% wheatAndRice], " (", levels(yieldData$crop), ")"), 
       title = "S_water (Crop-cultivar)", 
       fill = cropColours)

dev.off()
## png 
##   2
knitr::include_graphics(plotName)

Calculate correlation and linear models fitness:

linearModels.table <- data.frame(
  levels(yieldData$crop),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop)),
  numeric(nlevels(yieldData$crop))
)

names(linearModels.table) <- c("crop", "correlation_Pearson", "intercept", "intercept_p", "speed", "speed_p", "adjrsquared")

for (aCrop in levels(yieldData$crop))
{
  linearModels.table$correlation_Pearson[linearModels.table$crop == aCrop] <- 
    cor(x = yieldData$albedo[yieldData$crop == aCrop], y = yieldData$yield[yieldData$crop == aCrop], use = "pairwise.complete.obs")
  
  linearModel <- lm(yield ~ albedo, data = yieldData[yieldData$crop == aCrop,])

  linearModels.table$intercept[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,1]
  linearModels.table$intercept_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[1,4]
  linearModels.table$speed[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,1]
  linearModels.table$speed_p[linearModels.table$crop == aCrop] <- summary(linearModel)$coefficients[2,4]
  linearModels.table$adjrsquared[linearModels.table$crop == aCrop] <- summary(linearModel)$adj.r.squared
}
knitr::kable(linearModels.table)
crop correlation_Pearson intercept intercept_p speed speed_p adjrsquared
‘rice’ 0.1356812 182.9596 0 130.89453 0e+00 0.0183769
‘wheat 1’ 0.0300694 312.8942 0 44.60619 2e-07 0.0008704
‘wheat 2’ 0.0292444 321.8016 0 44.00976 5e-07 0.0008214