Skip to content

Producing plot using polygon function

4 messages · avinash barnwal, Uwe Ligges

#
On 18.11.2011 23:48, avinash barnwal wrote:
Defining *empty* vectors is almost never what you really want to do.
Running a loop 1:length is dangerous if a length is < 1, run it 
seq_along(.).
You meant a3[i], I guess.
At the end of this loop, this obviously simplifies to:

l <- a2 > a3
x <- a2[l]
y <- a3[l]
temp_time <- time[length]
Since you don't use anything from inside your loop here, why do you run 
that at all? Is this homework?

Uwe Ligges
#
On 19.11.2011 20:19, avinash barnwal wrote:
ggplot2 may be a nice package, but it won't help if you do not 
understand the underlying issues. Your code is too incomplete so that we 
cannot fix it. Better think about how you would draw a polygon manually 
and what you did in R.

And note that in

polygon(c(time[1:j],time[1:j]),c(x,y),col="grey")

Your time vector does not fit to x nor y (and you probably want to 
reverse the second entries in each c() call.

Uwe Ligges