Below the description of how the data can be cropped to an specific latitude and longitude. The following code contain the exact commands used to create Figures 3 and 4 for the manuscript. Note that all three used the same commands, the only difference was the latitude and longitude selected. Hence, the example below is only for one of them.
For the plots you would need to load or install the raster and rasterVis packages.
if(!require("raster")) install.packages("raster")## Loading required package: raster
## Loading required package: sp
if(!require("rasterVis")) install.packages("rasterVis")## Loading required package: rasterVis
## Loading required package: terra
## terra version 1.2.10
## Loading required package: lattice
## Loading required package: latticeExtra
Lets say we want to plot the data for the mean monthly composites of sea surface temperature (SST).
sst_tif <- list.files(path = "../../Data/SST monthly/",
pattern = "(mean).*tif$", # read only the mean
recursive = TRUE, # recursive checks all inside folders
full.names = TRUE)
stack_sst <- stack(sst_tif)
names(stack_sst) <- month.abb This will set the names of our layers in accordance to the month they represent numerically
Now we can determine coordinates we would like to look at
crop_1 <- extent(-77.47199754307310116, -71.70063605775197857,
34.67908943905803199, 40.54291599490499465)
raster_1 <- crop(stack_sst, crop_1)To plot our cropped data we use the function levelplot from the rasterVis package
lp_1 <- levelplot(raster_1)
lp_1If you want to save your plot as a high resolution picture you can save it as a tiff.
#Create a new directory to store your figures
dir.create("Figures")
tiff(filename = "./Figures/Temp_Zone_SST.tiff",
width = 7, height = 5, units = "in",
compression = "lzw", res = 300)
lp_1
dev.off()The same way we have manipulated the SST data we can manipulate the SST yearly, as well as, the CHLO-a monthly and yearly data.
Reference: https://oscarperpinan.github.io/rastervis/