0

I used R to make density surface models of whales in GGPLOT. However, l can not work out how to get the model into a raster so i can use it in QGIS. I have been trying as below but the squares of the model become stretched and it is not in the right place on the coastline.

#remove the back ground
final <- p + theme(legend.position = "none",
          panel.grid = element_blank(),
          axis.title = element_blank(),
          axis.text = element_blank(),
          axis.ticks = element_blank(),
          panel.background = element_blank()) 
#make raster
ggsave(plot=final, "XY.tiff", device = "tiff")
raster <- stack("XY.tiff")
lat_long <- ggplot_build(p)$layout$panel_params[[1]][c("x.range","y.range")] 
extent(raster) <- c(lat_long$x.range,lat_long$y.range)
crs(raster) <-"+proj=utm +zone=13 +datum=WGS84"
writeRaster(raster,"abundance.tif", overwrite=TRUE)

When i change the position "x.range" and "y.range" in the extent line, the model is the right shape but the lat lon has been reversed and the model is no where near Mexico anymore.

Does anyone have any idea how to get this map out of R and into QGIS?

l did not use a stack but instead used a prediction grid in the format of CSV file.

1 Answer 1

0

Your question reminds me of a quote from a smart fellow: "You're trying to get back the fish after making fish soup".

You should be saving to a "*.tif" raster file the density that you created before touching ggplot2. Making a non-georeferenced plot with ggplot, then trying to recreate the coordinate referencing is somewhat backwards. Can you show us the full code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.