Reputation: 1711
Context
I am using terra::rast()
to read a nc
file and plot it.
But the ploted map is upside down.
When I used raster::raster()
to read the nc
file and plot it. The map is right.
Question
How can I make the upside down map right when using terra::rast()
to read the nc
?
Reproducible code
I have uploaded pm2.5_year_2013.nc
data on my github.
The data can be found at here
library(terra)
air = rast('pm2.5_year_2013.nc')
plot(air) # an upside down China map
air2 = raster::raster('pm2.5_year_2013.nc')
plot(air2) # an right China map
Upvotes: 0
Views: 471
Reputation: 47411
It looks like this was fixed in the development version of "terra" (or the version of GDAL that it uses on windows)
install.packages('terra', repos='https://rspatial.r-universe.dev')
And now it works as expected.
library(terra)
#terra 1.6.30
r <- rast("pm2.5_year_2011.nc")
plot(r)
Upvotes: 2
Reputation: 20444
I am guessing this is a quirk of the data rather than than the terra
package. I didn't try loading it in raster
though - it does seem strange it would be the other way round in a different package.
In any case you can use terra::flip()
to make it the right way around.
air2 <- terra::flip(air, direction="vertical")
plot(air2)
Upvotes: 2