[R] Contour plots in R Studio

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Tue May 13 03:41:48 CEST 2014


Granted, you are new here, but reading the Posting Guide is advice included in every post on this list. One key recommendation found there is to not post in HTML, as we don't see what you see when you do that. Use plain text email.
Another key piece of advice in the Posting Guide is to provide a reproducible example. That means enough code that we see the a reasonable subset of the data you are working with in our R environments. I think [1] is a helpful guide to communicating in a reproducible fashion about R questions. It is not clear from your discussion that you have actually imported and worked with your data yet, but you may have to read enough documentation to actually do so before we can make progress on this question.
It looks to me like you need to study indexing in "An Introduction to R", because that understanding will allow you to turn your 3D problem into a series of 2D problems. Depending how your data are stored, finding the mean may involve the apply or rowSums functions, or some nested for loops.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On May 12, 2014 2:27:54 PM PDT, Lydia Keppler <lydiakeppler at gmail.com> wrote:
>Hi all,
>
>I am using Windows 7 and R Studio version 3.0.2 (2013-09-25).
>I am relatively new to R and am trying to make a contour plot from a 3D
>data grid.
>
>I my data file has the following specifics:
>
>[1] "file Data.nc has 3 dimensions:"
>[1] "time   Size: 96"
>[1] "lat   Size: 21"
>[1] "lon   Size: 61"
>[1] "------------------------"
>[1] "file Data.nc has 2 variables:"
>[1] "double U[time,lat,lon]  Longname:U Missval:1e+30"
>[1] "double V[time,lat,lon]  Longname:V Missval:1e+30"
>
>lat and lon includes latitude and longitude values from a certain
>region in
>a 1��grid
>time includes different months over 8 years
>
>I would like to draw
>1) a contourplot of the mean U (mean U of all times), at the different
>locations (x=lon, y=lat)
>2) a contourplot of U at the different locations (x=lon, y=lat) at
>different times.
>
>I have only made contourplots with 2D data (i.e. contour (lat,lon, z)
>and
>am struggling a bit to find help.
>
>Any suggestions are very much appreciated.
>Cheers,
>
>Lydia



More information about the R-help mailing list