[R] ploting several functions on the same plot

Duncan Murdoch murdoch.duncan at gmail.com
Thu Apr 4 02:07:11 CEST 2013


On 13-04-03 7:35 PM, Julio Sergio wrote:
> I want to superimpose two functions plots in the same page. The functions L0
> and L1, defined below
>
>
>    f0 <- function(mu, xm, ds, n) {
>      1 - pnorm((xm-mu)/(ds/sqrt(n)))
>    }
>
>    f1 <- function(mu,n) f0(mu, 386.8, 48, n)
>
>    L0 <- function(mu) f1(mu, 36)
>
>    plot(L0,ylim=c(0,1),xlim=c(360,420))
>
>    L1 <- function(mu) f1(mu,100)
>    lines(L1)
>
> The plot of L0 works pretty well. However, when trying to plot the second
> function, L1, the interpreter issues an error:
>
> Error in as.double(y) :
>    cannot coerce type 'closure' to vector of type 'double'
>
> How can I solve my problem, since I want to have both plots with the same
> quality? I mean, I don't want to produce an approximating polygonal for the
> second function.
>

curve(L1, add=TRUE) should handle it.

Duncan Murdoch



More information about the R-help mailing list