Hi:

You didn't specify what you meant in your original post by
"following that I had used didn't gave desired result" (sic).
I noted two potential problems: (i) the n in the plot is not what
you expected it to be, and (ii) the legend didn't render in the
range of values established by the graph you produced.

Problem (i) arises because
> seq(4:13)
 [1]  1  2  3  4  5  6  7  8  9 10
The sequence you actually wanted can be obtained either
by 4:13 or seq(4, 13):
> seq(4, 13)
 [1]  4  5  6  7  8  9 10 11 12 13
> 4:13
 [1]  4  5  6  7  8  9 10 11 12 13

Re the second problem, the x-axis of your graph
(when plotted correctly) runs from 4 to 13, but the x-coordinate
of your legend command starts at x = 30, so it won't appear
in the graphics window, but rather in the 'great beyond' :)

One way to get the graph and legend is to use matplot(),
because the x-axis will be the same in each curve rendered;
I observed that when using your code,
lines(*s, lty = ?)
used the x-values 1:10 rather than the 4:13 that you wanted.
An alternative is shown below.

I decided to put everything in a data frame, although this is not
strictly necessary:

dd <- data.frame(n = 4:13, pg, gs, ps)
# Plot all three curves together
with(dd, matplot(n, as.matrix(dd2[, -1]), type = 'l', lty = c(1, 2, 5), col
= 1,
                           xlab = 'n', ylab = 'Differences of the
variances') )
# Set up legend and insert it:
lx <- expression(var(t^3) - var(t^2), var(t^2) - var(t^1),
                           var(t^3) -  var(t^1))
legend(10, 0.0021, legend = lx, lty = c(1, 2, 5))

Using your code, this appears to work (pg, ps and gs same as yours):
n <- 4:13
plot(n, pg, type="l",xlab="n",
      ylab="Differences of the variances", ylim=c(-0.0012,0.0023) );
lines(n, gs,lty = 2)
lines(n, ps,lty=5)
legend(10, 0.0021, legend = lx, lty = c(1, 2, 5))

HTH,
Dennis


On Mon, Jul 5, 2010 at 9:41 PM, Shant Ch <sha1...@yahoo.com> wrote:

> Thanks Dr. Winsemius. Here's the toy data set.
>
> Basically pg = var(t^(3))-var(t^(2), gs = var(t^(2))-var(t^(1))    and
> ps=var(t^(3))-var(t^(1)). The revised code and the data set is as follows:
>
> n<-seq(4:13)
> pg<-c(-1.241394e-03, -9.738079e-04, -7.158755e-04, -5.343962e-04,
> -4.088778e-04, -3.202068e-04, -2.558709e-04, -2.079914e-04, -1.715435e-04,
>  -1.432430e-04)
> gs<-c(0.0022520038, 0.0020060234, 0.0017601434, 0.0015519810,
> 0.0013810851,0.0012407732, 0.0011245410, 0.0010271681, 0.0009446642,
> 0.0008740083)
> ps<-c( 0.0010106098, 0.0010322155, 0.0010442678, 0.0010175848,
> 0.0009722074,0.0009205665, 0.0008686700, 0.0008191768, 0.0007731207,
> 0.0007307653)
>
> plot(n, pg, type="l",xlab="n",ylab="Differences of the
> variances",ylim=c(-0.0012,0.0023) );
> lines(gs,lty = 2)
> lines(ps,lty=5)
>
> legend(30, 0.0021, expression( c ( var(t^(3))-var(t^(2)),
> var(t^(2))-var(t^(1))), var("t^(3))-var(t^(1)) ) ), lty=c(1,2,5)).
>
>
>
> ________________________________
> From: David Winsemius <dwinsem...@comcast.net>
>
> Cc: r-help@r-project.org
> Sent: Mon, July 5, 2010 9:43:19 PM
> Subject: Re: [R] Help in the legend()
>
>
> On Jul 5, 2010, at 8:06 PM, Shant Ch wrote:
>
> > Hi R-users,
> >
> > I was plotting the differences of the variances of the three estimators-
> T^(1), T^(2), T^(3), ofcourse taking two at a time. I was using the
> expression() in the legend function in order to show which line correspond
> to which of the difference, but the following that I had used didn't gave
> desired result. I would be grateful, if you help me out.
> >
> > plot(n, pg, type="l",xlab="n",ylab="Differences of the
> variances",ylim=c(-0.0012,0.0023), xlim=c(0,60));
> > lines(gs,lty = 2)
> > lines(ps,lty=5)
> >
> > legend(30, 0.0021, expression( c ( var(t^(3))-var(t^(2)),
> var(t^(2))-var(t^(1))), var("t^(3))-var(t^(1)) ) ), lty=c(1,2,5))
> >
>
> Have you consider offering a toy set of objects which defines "t", "n", and
> "pg".
>
> > Thanks.
> > Shant
> >
> >
> >
> >     [[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.
>
> David Winsemius, MD
> West Hartford, CT
>
>
>
>        [[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.
>

        [[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.

Reply via email to