|
| 1 | +pacman::p_load( |
| 2 | + Ipaper, data.table, dplyr, lubridate, |
| 3 | + ggplot2, gg.layers, ggrepel |
| 4 | +) |
| 5 | + |
| 6 | +# f = "./OUTPUT/PMLV2China_flux37_LAI_glass,ConstPC_gof.csv" |
| 7 | +# d = fread(f) |
| 8 | +indir = "./Project_PhotoPeriod/OUTPUT/" |
| 9 | + |
| 10 | +sites = c("儋州", "哀牢山", "西双版纳-Rubber", "西双版纳-EBF", "鼎湖山") |
| 11 | +# d[site %in% sites, ] |
| 12 | + |
| 13 | +# dat[GLASS <= -2] |
| 14 | +set_font() |
| 15 | + |
| 16 | +plot_Figure1 <- function(VAR="GPP", type_lai = "whit", |
| 17 | + x = "g1=false", y = "g1=true", |
| 18 | + lims = c(0.2, 1), thr = 0.02) { |
| 19 | + |
| 20 | + # file = "PMLV2China_flux37_LAI_glass,ConstPC_gof.csv" |
| 21 | + # dat_x = fread(glue("./Project_PhotoPeriod/OUTPUT/{file}")) |
| 22 | + # dat_y = fread(glue("./Project_PhotoPeriod/OUTPUT/Medlyn2011_V2/{file}")) |
| 23 | + dat_x = fread(glue("Project_PhotoPeriod/OUTPUT/Yu2004_(PC_photo=true,g1=false,g0=false)/PMLV2China_flux37_LAI_{type_lai},ConstPC_gof.csv")) # 对照组 |
| 24 | + |
| 25 | + dat_y = fread(glue("Project_PhotoPeriod/OUTPUT/Yu2004_(PC_photo=true,g1=true,g0=false)/PMLV2China_flux37_LAI_{type_lai},ConstPC_gof.csv")) # 实验组 |
| 26 | + |
| 27 | + ## Medlyn2011 |
| 28 | + # dat_x = fread("Project_PhotoPeriod/OUTPUT/Medlyn2011_(PC_photo=true,g1=false,g0=false)/PMLV2China_flux37_LAI_whit,ConstPC_gof.csv") |
| 29 | + |
| 30 | + # dat_y = fread("Project_PhotoPeriod/OUTPUT/Medlyn2011_(PC_photo=true,g1=false,g0=true)/PMLV2China_flux37_LAI_whit,ConstPC_gof.csv") |
| 31 | + |
| 32 | + # dat_x = fread(glue("{indir}/PMLV2China_flux37_LAI_{type_lai},{x}_gof.csv")) |
| 33 | + # dat_y = fread(glue("{indir}/PMLV2China_flux37_LAI_{type_lai},{y}_gof.csv")) |
| 34 | + |
| 35 | + df = listk(x = dat_x, y = dat_y) %>% melt_list("type") |
| 36 | + dat = df %>% |
| 37 | + select(-n_valid) %>% |
| 38 | + melt(c("type", "site", "var")) %>% |
| 39 | + dcast(site + var + variable ~ type, value.var = "value") %>% |
| 40 | + .[variable %in% c("NSE", "KGE", "R2"), ] |
| 41 | + |
| 42 | + brks <- c(thr, Inf) %>% c(-rev(.), .) |
| 43 | + pdat = dat[var == VAR & x >= lims[1] & y >= lims[1]] %>% |
| 44 | + mutate(diff = y - x, diff_lev = cut(diff, brks)) |
| 45 | + |
| 46 | + p <- ggplot(pdat, aes(x, y)) + |
| 47 | + geom_point() + |
| 48 | + geom_point(data = pdat[abs(diff) >= thr], aes(color = diff_lev), alpha = 0.8) + |
| 49 | + # geom_point(data = pdat[(WithPC - NonPC) <= -0.02,], color = "red", alpha = 0.8) + |
| 50 | + # geom_text_repel(data = pdat[abs(NonPC - WithPC) >= 0.02,], |
| 51 | + # aes(label = site), hjust = 0, vjust = 0, color = "blue") + |
| 52 | + geom_text_repel( |
| 53 | + data = pdat[abs(diff) >= thr], aes(color = diff_lev, label = site), min.segment.length = 0.2, |
| 54 | + hjust = 0, vjust = 0, alpha = 0.8) + |
| 55 | + # geom_text_repel(data = pdat[(WithPC - NonPC) <= -0.02,], |
| 56 | + # aes(label = site), hjust = 0, vjust = 0, color = "red", alpha = 0.8) + |
| 57 | + geom_abline(intercept = 0, slope = 1, linetype = 2, color = "red", alpha = 0.8) + |
| 58 | + coord_cartesian(xlim = lims, ylim = lims, expand = FALSE) + |
| 59 | + scale_color_manual(values = c("red", "darkgreen")) + |
| 60 | + theme(legend.position = "none") + |
| 61 | + labs(x = x, y = y) + |
| 62 | + # lims(x = lims, y = lims) + |
| 63 | + facet_wrap(~variable, scales = "free") |
| 64 | + prefix = toupper(type_lai) |
| 65 | + write_fig(p, glue("Figure3_{x}&{y}_{prefix}_{VAR}_v2.pdf"), 10, 4.5) |
| 66 | +} |
| 67 | + |
| 68 | +## LAI |
| 69 | +# type_lai = "whit" |
| 70 | +type_lai = "glass" |
| 71 | +# x = "ConstPC" |
| 72 | +# x = "NonPC" |
| 73 | +# y = "ConstPC" |
| 74 | +# y = "WithPC" |
| 75 | + |
| 76 | +# plot_Figure1("GPP", type_lai, thr = 0.02) |
| 77 | +plot_Figure1("ET", type_lai = "whit", lims = c(0.2, 0.9), thr = 0.02) |
| 78 | +plot_Figure1("ET", type_lai = "glass", lims = c(0.2, 0.9), thr = 0.02) |
0 commit comments