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) 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]]
David Winsemius
2016-Nov-05 00:43 UTC
[R] Using map with filled.contour doesn't display map
> 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
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]]