[R] Using map with filled.contour doesn't display map

David Winsemius dwinsemius at comcast.net
Sat Nov 5 18:31:40 CET 2016

> On Nov 5, 2016, at 9:33 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
> I get the error also (R3.3.1/raster2.5-8).
> Works fine if I call plot.new() before calling filledContour.

It didn't "work fine" when I did that. I first briefly see a generic plotting frame (x and y axes with no data) which was then blanked out and replaced with a colored  "strip  map" of temperatures but no map of continents. Further I get the message:

> library("ncdf")
Package 'ncdf' is deprecated and will be removed from CRAN shortly.
Use instead package RNetCDF or ncdf4 (for Windows from CRANextras)

I would further note that in the original sessionInfo() output there was no instance of `ncdf` only `ncdf4`. However, that doesn't explain the problem. The same behavior appears if I restart R and instead load ncdf4.

I was also unable to get any further plotting ... which was the original question, I thought. In particular this failed to update the <non-map-outlined> image.

filledContour( temp_file, plot.axes={axis(1); axis(2); map("world2", add=TRUE); points(0,0) })

If you look at map() you see that it also messes with the par('mar') values. I think the add=TRUE is overriding the plot=TRUE parameter to map.

I can get a subsequent `points(0,0)`-call to plot a point but the location is not correct on the y axis.

I think you would be better advised to start with map() and then fill in the colors using the values extracted from your NCDF file with the methods in the setup portion of filledContour.


> Given this is a contributed package you should be corresponding with the package maintainer if you think this solution is inappropriate or the documentation needs fixing, but I suspect you are better off being able to initialize the plot yourself.
> -- 
> Sent from my phone. Please excuse my brevity.
> On November 4, 2016 9:53:18 PM PDT, Jeff Charlton <jcharlto16 at gmail.com> wrote:
>> Hi David,
>> Thank you for the response.  I apologize that I didn't give a more
>> complete
>> example.  Here's code that recreates the issue I'm having on my system.
>> You'll have to enter the path to your packages and where you want to
>> store
>> the downloaded file.
>> library("maps", lib.loc="<your library location>")
>> library("raster", lib.loc="<your library location>")
>> library("ncdf", lib.loc="<your library location>")
>> download.file("
>> http://schubert.atmos.colostate.edu/~cslocum/code/air.sig995.2012.nc",
>> "<your path>/temp_file.nc")
>> temp_file = raster("<your path>/temp_file.nc")
>> filledContour(temp_file, plot.axes={axis(1); axis(2); map("world2",
>> add=TRUE)})
>> When this is run, you should get a plot that shows some contours
>> overlaid
>> on a map of world.  I originally wrote this several years ago. This
>> code
>> worked for me with the following versions of packages: R (3.0.1); ncdf
>> (1.6.6); maps (2.3-6); and raster (2.1-49).
>> Now, on my new, upgraded system, when I run this, I get a "plot.new has
>> not
>> been called yet" error.  If I then execute a plot.new() command and try
>> the
>> filledContour command again, I get the contours, but no map.  As I said
>> below, I believe something has changed in the maps package, but I can't
>> find anything in the documentation on it or an indication that others
>> are
>> having the same issue.  My current versions are:  R (3.3.2); ncdf4
>> (1.15);
>> maps (3.1.1); and raster (2.5-8).
>> I've changed from the ncdf package to the ncdf4 package, but I wouldn't
>> expect that to be an issue as that package is for reading netCDF files
>> into
>> R and that isn't an issue (i.e. I can do a plot(temp_file) to see that
>> the
>> file has been loaded properly)
>> Thanks for your time,
>> Jeff
>> On Fri, Nov 4, 2016 at 6:43 PM, David Winsemius
>> <dwinsemius at comcast.net>
>> wrote:
>>>> On Nov 4, 2016, at 11:26 AM, Jeff Charlton <jcharlto16 at gmail.com>
>> wrote:
>>>> Hello,
>>>> I'm trying to overlay a map on top of data showing temperatures
>> across
>>> the
>>>> world. The code I'm using is:
>>>>     filledContour(tempdata, plot.axes={axis(1); axis(2);
>> map("world2",
>>>> add=TRUE)})
>>>> where tempdata is a raster file made from a netcdf file downloaded
>> from
>>> the
>>>> NOAA website. The filledContour is a wrapper that translates the
>> raster
>>>> image into something that can be used by filled.contour.
>>>> If I run the code:
>>>> filledContour(tempdata)
>>> It's somewhat difficult to advise since in one place you say you are
>> using
>>> filled.contour, but above you are writing filledContour (but are not
>> saying
>>> where this function comes from or offering the required `library`
>> call to
>>> set this up.). You are also not offering any data example. Suggest
>> you make
>>> this a complete example.
>>>> I get the image I want, but when I add the plot.axes parameter, I
>> get a
>>>> "plot.new has not been called yet" error in axis(1). If I run
>> plot.new()
>>>> and the original filledContour call, I get the same result as if I
>> just
>>> did
>>>> filledContour(tempdata) (i.e. no map is overlayed).
>>>> The kicker in all this is that this code worked a couple of years
>> ago. I
>>>> ran into this error when I recently dusted of my code and installed
>> the
>>>> latest version of R and its various packages. I have a feeling that
>>>> something has changed in the maps package but I can't find any
>> reference
>>> to
>>>> it online.
>>>> Can anyone help?
>>>> Thank you,
>>>> Jeff
>>>> Just in case, here's my session info:
>>>> R version 3.3.2 (2016-10-31) Platform: x86_64-w64-mingw32/x64
>> (64-bit)
>>>> Running under: Windows 7 x64 (build 7601) Service Pack 1
>>>> locale: [1] LC_COLLATE=English_United States.1252
>> LC_CTYPE=English_United
>>>> States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C
>>>> LC_TIME=English_United States.1252
>>>> attached base packages: [1] stats graphics grDevices utils datasets
>>> methods
>>>> base
>>>> other attached packages: [1] ncdf4_1.15 maps_3.1.1 XML_3.98-1.4
>>>> RCurl_1.95-4.8 bitops_1.0-6 raster_2.5-8 sp_1.2-3
>>>> loaded via a namespace (and not attached): [1] parallel_3.3.2
>> tools_3.3.2
>>>> Rcpp_0.12.7 grid_3.3.2 lattice_0.20-34
>>>>      [[alternative HTML version deleted]]
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide http://www.R-project.org/
>>> posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>> David Winsemius
>>> Alameda, CA, USA
>> 	[[alternative HTML version deleted]]
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

More information about the R-help mailing list