[R] Multiple Plotting help (lines don't always connect)

stephen sefick ssefick at gmail.com
Tue Aug 19 02:26:39 CEST 2008


I am trying to use the type="b" in the plot statement so that there
are indeed points where there is a real data point and then the linear
interpolation is between "points" that are seperated by NA.  The
symbol shows that only where the symbol is is where there is real
data, and I planned on relaying this caveat to the reader, but the
trend holds with the real data where there are no missing values for
20ish other sampling events.  I believe it is valid to use such a plot
because indeed you are missing the local dynamics, but the data from
the rest of the data supports the trend.  I am very aware that you
guys are not privy to how my data is actually set up, and some of
these questions seem to overstep, but I do put a lot of thought into
the things I do, doesn't mean that they are right, and I am just
trying to make R do what I want.  I appreciate all of your comments
and suggestions as they make me think about my assumptions, and if
warranted reevaluate them.  I am still having problems with making
this work as I want, but that is probably my short coming.
thanks agian

Stephen Sefick

On Mon, Aug 18, 2008 at 7:50 PM, hadley wickham <h.wickham at gmail.com> wrote:
>>> Doesn't a line plot inherently display a set of linear interpolations?
>>
>> Yes.  And your point is?
>>
>> Compare:
>>
>> x <- 1:10
>> y <- rep(1:2,5)
>> y[5] <- NA
>> y0 <- approx(x,y,xout=1:10)
>> plot(y0,type="l")
>>
>> with
>>
>> foo(x,y)
>>
>> where
>>
>> foo <- function(x,y,...) {
>> plot(x,y,type="n",...)
>> na <- apply(cbind(x,y),1,function(x){any(is.na(x))})
>> f <- c(na[-1],FALSE)
>> x <- x[!na]
>> y <- y[!na]
>> f <- f[!na]
>> n <- length(x)
>> f <- f[-n]
>> segments(x[-n],y[-n],x[-1],y[-1],lty=ifelse(f,3,1))
>> }
>>
>> There is a difference in what you are telling the reader/viewer.
>
> But why is 4-6 special?  What makes it different to 1-2 and 2-3 and
> ...  Without more information there is no way for the reader to tell
> where the measured values are - i.e. they could be every 1 with 1
> missing values, every 0.5 with 2 missing values, or other completely
> different pattern.
>
> I'd argue what you (almost) always want is:
>
> plot(y0,type="l")
> points(y)
>
> then you can see exactly where the measurements are.  The only time
> that this isn't necessary is when you have a perfectly regular
> sampling on x, and the reader knows that it exists (i.e. from a
> caption or prior knowledge)
>
> Hadley
>
> --
> http://had.co.nz/
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

	-K. Mullis



More information about the R-help mailing list