我希望.gitignore
文件中有一些行忽略整个目录及其子目录,除了以 .pdf 结尾的任何文件(及其文件夹结构)
目前我使用;
outputs/*
!outputs/**/*.pdf
这排除了输出目录,然后似乎包括随机选择的子目录和.csv和.png。
文件夹结构并非固定到PDF文件(可能是1到8个子目录深度),但我只想让.pdf文件只保留在该outputs/
文件夹中。说实话,我觉得自己做的是对的!
我希望.gitignore
文件中有一些行忽略整个目录及其子目录,除了以 .pdf 结尾的任何文件(及其文件夹结构)
目前我使用;
outputs/*
!outputs/**/*.pdf
这排除了输出目录,然后似乎包括随机选择的子目录和.csv和.png。
文件夹结构并非固定到PDF文件(可能是1到8个子目录深度),但我只想让.pdf文件只保留在该outputs/
文件夹中。说实话,我觉得自己做的是对的!
我有一堆terra::rast()
连续数据,我将其分为 n 类,转换为因子并在离散尺度上绘制。
但是,当第一个栅格不具备其他栅格所具备的所有因子(例如,只有 3 个分类值,而不是全部 10 个,转换为因子)时,图就会变得有点混乱。
我正在寻找一种方法来告知 rast 堆栈(或图),整个堆栈的级别是堆栈的最小值 - 最大值,但某些层可能较少。
有趣的是,如果第一层包含所有可能的类/因素,那么后续层就可以了,并且情节也很好。
# dummy data
library(terra)
r1 <- rast(nrows = 10, ncols = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10)
r1[] <- runif(ncell(r1), min = 1, max = 5) # Random values between 1 and 5
r2 <- rast(nrows = 10, ncols = 10, xmin = 0, xmax = 10, ymin = 0, ymax = 10)
r2[] <- runif(ncell(r2), min = 1, max = 5)
# Combine rasters into a stack
s <- c(r1/r1, r1/r2, r2/r1, r2/r2)
names(s) <- c("r1/r1", "r1/r2", "r2/r1", "r2/r2")
# Reclassify the raster stack
# Define reclassification matrix
m_rc <- matrix(c(0, 0.5, 1,
0.5, 0.9, 2,
0.9, 1.1, 3,
1.1, 2, 4,
2, max(global(s, max, na.rm=T)$max), 5),
ncol = 3, byrow = TRUE)
# Apply reclassification
s_r <- classify(s, m_rc)
# Convert reclassified raster to factor for categorical plotting
s_r_f <- as.factor(s_r)
# Step 3: Plot using ggplot2 and tidyterra with custom legend labels
ggplot() +
geom_spatraster(data = s_r_f) +
facet_wrap(~lyr, nrow = 2) + # Separate plots for each layer
scale_fill_manual(
values = c("blue","lightblue" , "white", "yellow", "red"), # Assign custom colors
na.value = "transparent", # Transparent for NA values
) +
labs(
title = "Reclassified Raster Stack",
labels = c("0 - 0.5","0.5 - 0.9","0.9 - 1.1","1.1 - 2","> 2"),
fill = "Class"
) +
theme_minimal()