Transformation and export from R of a ggplot map to raster file (tiff)

In R, i have run his code

ordinary kriging

mydata.krig <- krige(Clay~1, train_data, newdata=mask, vgm)

names(mydata.krig)[1] <- "Clay.pred"

min(mydata.krig$Clay.pred, na.rm=T); max(mydata.krig$Clay.pred, na.rm=T) ggplot() +
geom_stars(data = mydata.krig["Clay.pred"]) +
scale_fill_gradient(low = "yellow", high = "dark blue", limits = c(15.5486,61.41131)) +
geom_sf(data = thessaly_smus, color = "black", fill = NA, size = 1) +
labs(title = "%Clay Predicted Values - Ordinary Kriging, OK")
and with the ggplot i have aqcuired a map of the predicted values of %Clay. I want to extract this map as a raster file from R in order to open it in a GIS. Provide me accurate code for this.
Screenshot 2023-06-29 205818
From the screenshot you can see, I want the new raster to be the area of interest (polygons) and not the entire picture..

Thanks for the help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.