[R] Multiple Plotting help (lines don't always connect)
Rolf Turner
r.turner at auckland.ac.nz
Tue Aug 19 00:47:14 CEST 2008
On 19/08/2008, at 10:15 AM, hadley wickham wrote:
> On Mon, Aug 18, 2008 at 3:54 PM, Rolf Turner
> <r.turner at auckland.ac.nz> wrote:
>>
>> On 19/08/2008, at 1:04 AM, stephen sefick wrote:
>>
>>> The real data are counts of aquatic insects at distinct locations
>>> on a
>>> river continuum on the way down a river, so the when a point
>>> point on
>>> the graph is missing (lost sampling equipment for that month) the
>>> points downstream (toward the right) are valid to show a trend.
>>> Aren't they?
>>
>> Quite possibly; I wouldn't really know. However it would be less
>> than
>> honest to plot the interpolated/inferred points as if they were
>> genuine
>> data points. By all means plot the interpolations, but
>> distinguish them,
>> e.g. by joining them to their neighbours by dotted lines (where
>> real points
>> are joined to each other by solid lines).
>
> x <- sort(runif(10))
> y <- runif(10)
>
> plot(x, y, type="l")
>
> 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.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list