[R] plotting a distribution curves

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Sep 4 05:06:02 CEST 2003

Rajarshi Guha <rajarshi at presidency.com> wrote:
	  is there a way to plot distribution curves (say normal or chi sq etc)
	from within R?
	For example I looked up the *chisq family of functions but I'm not sure
	as to how I would use them to generate a plot of the chi sq distribution
	(for arbitrary d.o.f).
Perhaps the most obvious way:
    x <- seq(0, 30, length=101)
    plot(x, dchisq(x, df=8))

Another way:
    curve(dchisq(x,df=8), from=0, to=30)

As someone has recently noted, code that depends on the textual
form of something is often subtly wrong, which is why I think that
"curve" and similar functions are best avoided.  A third way that
is better than "curve" is

    plot(function(x) dchisq(x,df=8), from=0, to=30)

in which the name of the argument x no longer matters.

This can of course be used with any function, not just a c* function.

More information about the R-help mailing list