Re: [R] contour plot

2009-07-22 Thread David Winsemius


On Jul 22, 2009, at 10:17 AM, axionator wrote:


Hi,
I want to draw a contour plot of the following function:

z = y*x + epsilon,

where x ~ N(y, 1)
and epsilon ~ N(0, sigma) with sigma fixed (e.g. 1)

But didnt manage to feed "contour" with the right input.

Thanks for your help.
Armin


The help page has an example that appears be straightforward. If you  
have made any attempt, then you should include it in your request.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot

2009-07-23 Thread axionator
That problem is that for every y I get a different x and thus cant
create an array as in the help page examples.
I was just wondering, whether there is a possibility to create such a
contour plot easily without having to spend too much time with setting
up a suitable matrix manually.

Armin

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot

2009-07-23 Thread Petr PIKAL
Hi

maybe package akima with function interp can help you

Regards
Petr

r-help-boun...@r-project.org napsal dne 23.07.2009 11:04:25:

> That problem is that for every y I get a different x and thus cant
> create an array as in the help page examples.
> I was just wondering, whether there is a possibility to create such a
> contour plot easily without having to spend too much time with setting
> up a suitable matrix manually.
> 
> Armin
> 
> __
> R-help@r-project.org mailing list
> 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.

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot

2009-07-23 Thread ONKELINX, Thierry
Have a look at the reshape and ggplot2 package. 

ds <- matrix(rnorm(100), nrow = 10)
library(reshape)
molten <- melt(data = ds)
library(ggplot2)
ggplot(molten, aes(x = X1, y = X2, z = value)) + geom_contour()

HTH,

Thierry 




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens axionator
Verzonden: donderdag 23 juli 2009 11:04
Aan: David Winsemius
CC: r-help@r-project.org
Onderwerp: Re: [R] contour plot

That problem is that for every y I get a different x and thus cant
create an array as in the help page examples.
I was just wondering, whether there is a possibility to create such a
contour plot easily without having to spend too much time with setting
up a suitable matrix manually.

Armin

__
R-help@r-project.org mailing list
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.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

__
R-help@r-project.org mailing list
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.


Re: [R] Contour Plot Aspect Ratio

2008-10-03 Thread Greg Snow
The squishplot function in the TeachingDemos package will adjust margins to 
give the desired aspect ratio with the whitespace outside of the plot rather 
than inside.  However the filled.contour function sets its own margins inside 
of the function so this does not work with filled.contour.  You could try it 
with the image function, or you may want to try using levelplot in the lattice 
package for another way to do filled contour plots that may work better for you.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> project.org] On Behalf Of Sam Albers
> Sent: Thursday, October 02, 2008 2:02 PM
> To: r-help@r-project.org
> Subject: [R] Contour Plot Aspect Ratio
>
> Hello there,
>
> I have a fairly simple request (I hope!)
>
> I have produced a filled contour plot like this:
>
> library(grDevices)
> library(gplots)
> library(plotrix)
>
> filled.contour(contour, axes=F, frame.plot=TRUE, color=terrain.colors,
> ylab=
> "Length Along Flume (m)", key.title = title(main="Velocity\n(m/s)"),
> key.axes = axis(4, seq(0, 0.6, by = 0.1)), asp=2, plot.axes = {
> axis.mult(side=1,mult=0.005,mult.label="Width (cm)")
> axis(side=2, at=x, labels=colnames(contour)) })
>
> Note the asp=2 argument.
>
> I would like to make this plot twice as long as it is wide. I
> accomplish
> this using asp=2 but the actual box that I am plotting now is too big
> for
> the data contained within.
>
> Here is what it looks like:
>
> http://docs.google.com/Doc?id=ddqdnxbq_30ffthshgk
>
> Does anyone know how I might be able to lengthen this graph without it
> looking like this? I want to suck in that vertical axes so that it is
> snug
> with the actual contour plot.
>
> Thanks in advance.
>
> Sam
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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.

__
R-help@r-project.org mailing list
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.


Re: [R] Contour Plot Aspect Ratio

2008-10-03 Thread Sam Albers
So I managed to solve this for myself in a very roundabout kind of way. So I
figured that I should share in case anyone else needed something like this.

filled.contour(contour, axes=F, frame.plot=F, color=terrain.colors, ylab=
"", key.title = title(main="Velocity\n(m/s)"),asp=2, key.axes = axis(4,
seq(0, 0.6, by = 0.1)), plot.axes = {
axis.mult(side=1,mult=0.005,mult.label="Width (cm)")
axis(side=2, at=x, line = -5, labels=colnames(contour)) })
mtext(side=2, line=-1.5, 'Length Along Flume (m)')

I just removed the frame.plot then manually shifted the axes and axes label
over until they lined up nicely with the edge of the actual contour plot.
Anyways, this is solved and thank you for your help.

Sam

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot - smooth lines

2008-12-27 Thread Uwe Ligges



tommaso.lette...@unifi.it wrote:

Dear R-Users,
I am using 'contour' to plot a graph using values x,y and a matrix z.
I would like to obtain 'smooth lines' instead of no-smooth contour lines.
I tried with filled.contour too.
In a Post I found
yy <-predict(interpSpline(x, y))
I could use that method for each range that I want to plot but I hope to 
find a easier method.


You could also increase the resolution, but that makes your graphics 
rather huge...


Uwe Ligges




Thank you

Tommaso Letterio
DIAF - UniFi
Via San Bonaventura 13
Firenze (IT) - 50145
+39-055-3288605

__
R-help@r-project.org mailing list
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.


__
R-help@r-project.org mailing list
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.


Re: [R] Contour plot (level curves)

2007-10-04 Thread Prof Brian Ripley
On Thu, 4 Oct 2007, Caio Azevedo wrote:

> Hi all,
>
> I have a sample of n values from a bivariate distribution (from a MCMC
> procedure). How could I draw a contour plot of "the joint density" based on
> that sample ?

You need to estimate the density, and contour that estimate.  MASS has 
examples using its kde2d function.  There are other methods available, 
e.g. in package sm.

>
> Sorry if I was not too clear.
>
> Thans in advance,
>
> Regards,
>
> Caio
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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.
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
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.


Re: [R] Contour plot (level curves)

2007-10-04 Thread hadley wickham
On 10/4/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> On Thu, 4 Oct 2007, Caio Azevedo wrote:
>
> > Hi all,
> >
> > I have a sample of n values from a bivariate distribution (from a MCMC
> > procedure). How could I draw a contour plot of "the joint density" based on
> > that sample ?
>
> You need to estimate the density, and contour that estimate.  MASS has
> examples using its kde2d function.  There are other methods available,
> e.g. in package sm.

If you want something ready made, ggplot2 uses kde2d to draw contours
from a kernel density estimate -
http://had.co.nz/ggplot2/stat_density_2d.html

Hadley


-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
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.


Re: [R] Contour plot (level curves)

2007-10-05 Thread Eric Elguero
> I have a sample of n values from a bivariate distribution (from a MCMC
> procedure). How could I draw a contour plot of "the joint density" based on
> that sample ?

here is a fast 2D density estimator. Not very sophisticated, but works.
The function assumes that data are in the form of a matrix
with (first) two columns containing x and y coordinates.

To plot the result:
image(dens2d(x)) or contour(dens2d(x))

Play with the h parameter to change the smoothness of the surface.


>dens2d
function(x, nx = 20, ny = 20, margin = 0.05, h = 1)
{
 xrange <- max(x[, 1]) - min(x[, 1])
 yrange <- max(x[, 2]) - min(x[, 2])
 xmin <- min(x[, 1]) - xrange * margin
 xmax <- max(x[, 1]) + xrange * margin
 ymin <- min(x[, 2]) - yrange * margin
 ymax <- max(x[, 2]) + yrange * margin
 xstep <- (xmax - xmin)/(nx - 1)
 ystep <- (ymax - ymin)/(ny - 1)
 xx <- xmin + (0:(nx - 1)) * xstep
 yy <- ymin + (0:(ny - 1)) * ystep
 g <- matrix(0, ncol = nx, nrow = ny)
 n <- dim(x)[[1]]
 for(i in 1:n) {
  coefx <- dnorm(xx - x[i, 1], mean = 0, sd = h)
  coefy <- dnorm(yy - x[i, 2], mean = 0, sd = h)
  g <- g + coefx %*% t(coefy)/n
 }
 return(list(x = xx, y = yy, z = g))
}

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot - line passing through z values

2008-06-19 Thread Duncan Murdoch

On 6/19/2008 12:51 PM, Jehol wrote:

Dear all,
there is much in these forums about adding a line to a
contour/filled.contour plot, but I haven't found hints for the following. I
apologize in advance if I just missed the right one.

I'm having a standard filled.contour plot to which I want to add a line
passing through some specific z-values at some specific x, without knowing
the y coordinates. There should be a way of getting these coordinates
(within the accuracy defined by nlevels in the initial filled.contour) but
I'm not sure how to do that, particularly as filled.contour does not return
any values.

If anyone's got any idea...please help.


The contourLines function will return x and y values corresponding to a 
contour.  You could search that result for a segment that crosses the x 
value of interest.


Duncan Murdoch

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot, failing to interpolate through all data

2008-11-04 Thread Dieter Menne
Folkes, Michael  dfo-mpo.gc.ca> writes:

> I'm having trouble making contour lines for this attached, sparse
> dataset (low data:NA ratio!).  Is it the high number of NA's, or funny
> layout of the densities, or something else that's causing this?  
> 
> start data to be in file='testmatrix.csv'
> 
> "0.5","1","1.5","2","2.5","3"
> "-0.833",NA,NA,NA,NA,NA,21.05
> "-0.8",NA,NA,NA,NA,10.62,NA
> "-0.75",NA,NA,NA,5.13,NA,NA
> "-0.667",NA,NA,2.24,NA,NA,11.68

contour needs a more data, it's rather a plotting workhorse and not so good for
interpolation.
There are examples for spatial statistics in library/MASS/scripts/ch15.R and in
"the book" by Venables/Ripley. You might also search for "geo" in the packages,
because your problem is fairly common in geographical ecology.

Dieter

__
R-help@r-project.org mailing list
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.


Re: [R] contour plot or persp plot with log scale?

2009-02-12 Thread Uwe Ligges



Gilbert Brenes wrote:

Hi.

Is it possible to draw a contour plot (with contour or filled contour) 
or a a surface plot (with persp or persp3d) with the z axis in a log scale?



At least for contour(), you can specify logarithmic breaks.

Best,
Uwe Ligges



Gilbert

__
R-help@r-project.org mailing list
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.


__
R-help@r-project.org mailing list
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.


Re: [R] contour plot or persp plot with log scale?

2009-02-12 Thread Duncan Murdoch

On 2/12/2009 12:04 PM, Gilbert Brenes wrote:

Hi.

Is it possible to draw a contour plot (with contour or filled contour) or a 
a surface plot (with persp or persp3d) with the z axis in a log scale?


For persp or persp3d I think you'd have to do the log transformation 
yourself.  For example,


x <- 1:100
y <- 1:100
z <- outer(x,y, function(x, y) exp(x/10 + y/10)
logz <- log(z, 10)
persp3d(x,y,logz, axes=FALSE, zlab="z", col="red")
axes3d(c("x", "y"))
axis3d("z", at=pretty(logz), labels=10^pretty(logz))

Duncan Murdoch

__
R-help@r-project.org mailing list
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.