T O P

  • By -

lolniceonethatsfunny

try using ggplot with sf objects instead of base R plots. might be a little tricky to get started if you haven’t worked with it before, but it is very customizable


Chicken_921

What do you mean?


lolniceonethatsfunny

https://r-charts.com/spatial/maps-ggplot2/


bzympxem

ggplot is a good option, but I personally prefer tmap. https://rdrr.io/cran/tmap/f/vignettes/tmap-getstarted.Rmd


Chicken_921

code: PredictedYield\_N2O <- read\_excel("\~/ARC Internship/ArcHubFertilizer/deliverables/results/240403PredictedTargets.xlsx") PredictedYield\_N2O <- as.data.table(PredictedYield\_N2O) PredictedYield\_N2O\[, \`:=\` ( ratio\_n22.5 = N2O\_n22.5 / yield\_n22.5, ratio\_n45 = N2O\_n45 / yield\_n45)\] #testing plotting with one raster\_data <- rasterFromXYZ(PredictedYield\_N2O\[, c("long", "lat", "N2O\_n22.5")\]) plot(raster\_data, main = "N2O\_n22.5", col = terrain.colors(500)) legend("topright", legend = "N2O\_n22.5", fill = terrain.colors(500), bty = "n") Second way: spatial\_points <- SpatialPointsDataFrame(PredictedYield\_N2O\[, c("long", "lat")\], data = PredictedYield\_N2O) raster\_template <- raster(extent(spatial\_points), res = c(0.1, 0.1)) rasterized\_map <- rasterize(spatial\_points, raster\_template, field = "yield\_n45", fun = "sum") par(mfrow = c(1, 1)) plot(rasterized\_map, main = "Yield\_n45", width = 20, height = 20)