I need to plot some data from NetDef File (1.1MB).
The file has a 413x22 9 grid (9 4577 points) in every point of the rain value that I have to print in the right lawn lawn. The grid is not necessarily static, so we have two additional 413x22 9 variables (XLAT and XLON), which include the values of latitude-characters for each grid point.
Thanks for the signals of these questions ...
... using ggplot is quite simple plotting data on an arbitrary grid:
Library (ncdf4) Library (GG Plot 2) Library (Reshaping) ncfile & lt; - nc_open (inputfile Ncvar_get (ncfile, "pr") Pr & lt; - pr * 86400 mpr & lt; - melt (PR) Ggplot (AES (X = X1, y = X2, fill = value), data = MMP) Geom_raster () + coord_equal ()
This will produce a plot with a grid, which is definitely not latitude. However, to plot the same data with the correct grid try:
xlon & lt; - ncvar_get (ncfile, "xlon") xlat & lt; - ncvar_get (ncfile, "xlat") df & lt; - Detakfrem (as .vector (lat), as.vector (lon), as.vector (pr)) ggplot (aes (x = lat, y = lon, fill = pr), data = df) + geom_raster () + Coord_equal () < / Code>
ggplot a "they A big error "and the plot will not return.
pr, lat and lon are 413x229 arrays.
Then the question:
- What am I doing wrong?
- How can I easily optimize the stable non-continuous contour level in ggplot?
- How can I overlay the political map of the area that is plotted? (Alps ) I have not seen it yet because it is of secondary importance. One of the questions above can be answered, so feel free to ignore it. Edit: The answer states that I should use the
raster and raster package though, I'm not sure that this How to do. File does not provide any more information I know that it is Lamber Knforml projection: latitude_of_projection_origin = 39. longitude_of_projection_origin = 14. Mank_priwartn = 35., 51. grid_factor = 0.684241343018562
You can see it by "NCD-H"
Although I do not understand how to use
levelplot ()
on the right latitude-grid. It really is a problem for me. I know how to do this in Grad, just enough, but Grad is very limited and I honestly want to avoid using it.
I remember that there are problems like you
Here I have learned: is
as far as I know, ggplot the geom_raster
has plot only on a regular localized grid, and if you unpublished latitude and graphs to raster, you may There can not be a regular grid to plot. If you are setting up to use ggplot to plot your data and you only have latitude and graphs, then you have to find projection related information and before its original, regular distance grid project Have to do. Uses projections provided by Ggplot mapproject
package and does not use projection libraries, which gives me R. More powerful and globally supported in other spatial packages.
If you are working with a regular grid, which I think is you, I recommend using the raster
package, which can be sent directly to NCTFF4 files Can read. For a simple conspiracy, try:
Library (raster) R & lt; - Raster ("your_nc_file_path", varnama = "pr") plot (r) contour (r, plus = TRUE)
If you have a properly formed NETDF file, Can also remove information such as proj4string (r)
or crs (r)
or projection (r)
. You may be able to translate it to work with ggplot projection systems.
In addition, if you really want to actually plot it in ggplot, then try using the rasterVis
package, which is easy to use with Ggplot Prepares Raster for
Library (Raster Wise) #Notes 'G' Plot (with Raster Wise) and `GG Plot JeepLot (R) + GOM_Tile (AES (fill = value))
< / Pre>Hope that helps.
Comments
Post a Comment