I have an hdf5 data file that has lat/long and a dozen of values, for example temperature. I would like to plot so I can visualize the data in a map style so with lat/long in the axis. Is there a direct way to do it? I only found a very complicated way on a blog. With netcdf data I can just use plot(ncvariable) and it will work, not with a hdf5 file.
I am using the rhdf5. If I read the h5 file and a specific value I only get a vector
> library(rhdf5)
> ncep<-h5read("CB_OL1_1979OCT.h5", "sh")
> head(ncep)
[1] 1.03953242 0.79024571 2.29503083 0.43957919 0.36909071 -0.04498866
I am attaching the file. I am not sure you would call it a 3d, it's a simple raster with x,y,value. h5 file
It's been some time since you asked, but in case you did not found a solution yet, I'd like to provide two approaches on how to handle this.
Since your hdf5 file is not available anymore, I just picked a random file provided here for illustration.
On the one hand, you could simply use
plot(grid = TRUE)
from{terra}
after having read your hdf5 file usingrast()
:Or you could go for the little bit more complex solution, generating graticules manually using
sf::st_graticules()
first, followed by making use of{tidyterra}
to be able to use{ggplot2}
with SpatRaster and SpatVector objects from{terra}
: