Skip to content

Problems trying to place a global map with Ncdf data plot

4 messages · r@i@1290 m@iii@g oii @im@com, Bert Gunter, Roy Mendelssohn - NOAA Federal +1 more

#
Hello there,

I am trying to overlay a global map with ncdf data of precipitation for a
particular location (using specific coordinates). The file is in ncdf format
(commonly used to store away climate data), and I am currently attempting to
place a global map on plotted precipitation values. However, I am having
difficulty placing a global map on this plot and am encountering errors. I
will show you what I have done:

#To create a plot of precipitation data using the following ncdf file - the
following works fine and provides the distributions global precipitation
values (Land+Water values):

library(ncdf4)
Can<-"MaxPrecCCCMACanESM2rcp45.nc"
maximum precipitation")
ylab="Latitude", xlab="Longitude", >main="Year 5 one-day maximum
precipitation (mm/day) for CanESM2 under RCP4.5", pretty=T,
col.regions=(rev(brewer.pal(10, "Spectral"))))

#To place a global map on the map that map that returns using the above
code. *This is where errors begin:
size=0.8)+borders("world",
colour="black")+scale_color_viridis(name="onedaymax")+theme_void()+coord_quickmap()
*Error: Aesthetics must be either length 1 or the same as the data (128): x,
y, colour*


Why doesn't this work? Could it be that I am not including the "time"
dimension in the ggplot function? The problem, though, is when I try to
obtain the "time" dimension, like I did for latitude and longitude, I
receive the following error:

t<-ncvar_get(Model,"time")
*Error in nc$dim[[idobj$list_index]] : 
? attempt to select more than one element*

If it helps, this is what the variables and dimensions look like in the ncdf
file:

/File MaxPrecCCCMACanESM2rcp45.nc (NC_FORMAT_NETCDF4):

? ? 3 variables (excluding dimension variables):
? ? ? ? double onedaymax[lon,lat,time]? (Contiguous storage)? 
? ? ? ? ? ? units: mm/day
? ? ? ? double fivedaymax[lon,lat,time]? (Contiguous storage)? 
? ? ? ? ? ? units: mm/day
? ? ? ? short Year[time]? (Contiguous storage)? 

? ? 3 dimensions:
? ? ? ? time? Size:95
? ? ? ? lat? Size:64
? ? ? ? ? ? units: degree North
? ? ? ? lon? Size:128
? ? ? ? ? ? units: degree East/

Any help would be greatly appreciated!!!!

Thanks,
#
The r-sig-geo list would probably be a better place to post this, as they
specialize in this sort of thing.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Feb 17, 2019 at 3:48 AM rain1290--- via R-help <r-help at r-project.org>
wrote:

  
  
#
Hi:
Maybe I am missing something (i am old and it is early on a Sunday),  but I don't see whee the dataset is defined in either ggplot or geom_point. You must have a data frame defined that contains both your expanded grid and the precipitation data and that has to be defined in either the ggplot() call or the geom_point() cal.

HTH,

-Roy

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
#
Hi rain1290,
I have recently been working on a similar project, building a grid of
event densities for geographic coordinates. If you are stuck, I may be
able to provide some assistance.

Jim

On Sun, Feb 17, 2019 at 10:49 PM rain1290--- via R-help
<r-help at r-project.org> wrote: