I'm an absolutely new one in R (it's my second day), it's a little bit difficult for me. So, sorry for this question, but I really need help.
I've already read R - Plotting netcdf climate data Plot NetCDF variable-grid data file using ggplot2: "Vector is too large" error but still don't understand.
I've got to plot NMF2 from this set of data in geo coordinates https://drive.google.com/file/d/0B6IqnlmRMSpcNFBXWWlha1JUUzQ/view?usp=sharing
The easiest way to do it was:
>library(raster)
>varRaster<-raster("F18-SSUSI_EDR-NIGHT-DISK_DD.20150107_SN.26920-00_DF.NC", varname="NMF2_DISK")
>cols <- rev(rainbow(255))
>plot(varRaster, col=cols)
Now I've got a plot, but the grid is not a geo one. So there are two questions:
- What I have to do to get the correct grid?
- How is it possible to add the world map layer?
Thank you in advance for your help.
UPGRADE
Taking a better look to my data I found out that I have to change missval to NA and also I need to transpose. The best variant I've found is this tutorial and everything is almost all right but the data is now strained all ower the map...And it has to be just a wide track of sattelites scan.
I can't put here the image, because my reputation is very low:(
library(raster)
library(ncdf)
data = open.ncdf("F18-SSUSI_EDR-NIGHT-DISK_DD.20150107_SN.26920-00_DF.NC")
lon=get.var.ncdf(data,"PIERCEPOINT_NIGHT_LONGITUDE")
lat=get.var.ncdf(data,"PIERCEPOINT_NIGHT_LATITUDE")
lon<-lon-180
dim(lat)
nmf2=get.var.ncdf( ex.nc, "NMF2_DISK")
nmf2[nmf2 == -1e+30] <- NA
dim(nmf2)
nmf2_un=get.var.ncdf( ex.nc, "NMF2_DISK_UNCERTAINTY")
nmf2_un[nmf2_un == -1e+30] <- NA
nmf2_1 <- raster(t(nmf2)[ncol(nmf2):1, ])
nmf2_un_1 <- raster(t(nmf2_un)[ncol(nmf2_un):1, ])
w <- brick(nmf2_1, nmf2_un_1)
projection(w) <- CRS("+init=epsg:4326")
extent(w) <- c(min(lon), max(lon), min(lat), max(lat))
plot(w[[1]])
library(maptools)
data(wrld_simpl)
plot(wrld_simpl, add = TRUE)
I would be very glad if somebody can tell me what's wrong!
UPDATE 2
Tried to use raster only. Still have a mistake with projection library(raster)
inputfile <- "F18-SSUSI_EDR-NIGHT-DISK_DD.20150107_SN.26920-00_DF.NC"
lat <- raster(inputfile, varname="PIERCEPOINT_NIGHT_LATITUDE")
lon <- raster(inputfile, varname="PIERCEPOINT_NIGHT_LONGITUDE")
plat <- rasterToPoints(lat)
plon <- rasterToPoints(lon)
lonlat <- cbind(plon[,3], plat[,3])
lonlat <- SpatialPoints(lonlat, proj4string = CRS("+proj=longlat +datum=WGS84"))
extent(lonlat)
#class : Extent
#xmin : 0.008961686
#xmax : 359.983
#ymin : -84.95161
#ymax : 89.68419
pr <- raster(inputfile, varname="NMF2_DISK")
extent(pr) <- extent(lonlat)
pr
#class : RasterLayer
#dimensions : 408, 13, 5304 (nrow, ncol, ncell)
#resolution : 27.69031, 0.4280289 (x, y)
#extent : 0.008961686, 359.983, -84.95161, 89.68419 (xmin, xmax, ymin, ymax)
#coord. ref. : NA
#data source : C:\Users\Svetlana\Science\GUVI\R\SSUSI\F18-SSUSI_EDR-NIGHT- DISK_DD.20150107_SN.26920-00_DF.NC
#names : NMF2_DISK
#zvar : NMF2_DISK
r <- projectRaster(pr, crs=CRS("+proj=longlat +datum=WGS84"))
#Error in projectRaster(pr, crs = CRS("+proj=longlat +datum=WGS84")) :
# input projection is NA
What's wrong?
And the other question is how to work with missval while using raster? I mean that in spite of using NA there is 8 000 000 for missed values of data. What I have to do with this?