[R] xyplot type="l"
Peter Ehlers
ehlers at ucalgary.ca
Sun Apr 15 19:46:03 CEST 2012
On 2012-04-15 09:31, David Winsemius wrote:
>
> On Apr 15, 2012, at 11:54 AM, Peter Ehlers wrote:
>
>> On 2012-04-15 03:19, Eiko Fried wrote:
>>> Probably a stupidly simple question, but I wouldn't know how to
>>> google it:
>>>
>>> xyplot(neuro ~ time | UserID, data=data_sub)
>>>
>>> creates a proper plot.
>>>
>>> However, if I add
>>> type = "l"
>>> the lines do not go first through time1, then time2, then time3 etc
>>> but in
>>> about 50% of all subjects the lines go through points seemingly
>>> random
>>> (e.g. from 1 to 4 to 2 to 5 to 3).
>>> The lines always start at time point 1, though.
>>>
>>> Defining "time" as factor or ordered doesn't change this.
>>> "neuro" is a numerical variable.
>>>
>>> It's probably some beginner's mistake, but I don't seem to be able
>>> to solve
>>> it.
>>
>> See if this gives a clue:
>>
>> library(lattice)
>> xyplot(Sepal.Length ~ Sepal.Width | Species, type = 'l',
>> data = iris)
>> ord<- with(iris, order(Sepal.Width))
>> iris2<- iris[ord,]
>> xyplot(Sepal.Length ~ Sepal.Width | Species, type = 'l',
>> data = iris2)
>>
> I hope Peter doesn't take offense when I opine that the improved
> version remains an ugly plot. Better would be:
>
> xyplot(Sepal.Length ~ Sepal.Width | Species,
> panel=function(x,y, ...){
> panel.xyplot(x,y, ...)
> panel.loess(x,y)},
> data = iris)
>
> OR:
>
> xyplot(Sepal.Length ~ Sepal.Width | Species,
> panel=function(x,y, ...){
> panel.xyplot(x,y,...)
> panel.lmline(x,y)},
> data = iris)
No offense taken, David.
This may well have been (and almost surely *should* have been) the OP's
unstated ultimate objective. I merely interpreted the question quite
literally as a desire to pass sequentially through all points which
of course the OP's code would indeed do, but clearly not in the order
desired.
Peter Ehlers
More information about the R-help
mailing list