[R] lattice question

Naresh Gurbuxani n@re@h_gurbux@n| @end|ng |rom hotm@||@com
Thu Aug 11 01:57:11 CEST 2022


Actually I meant types (e.g., lty = 1:2).  But colors would also work.  But I do not want to specify these in call to xyplot().

In my actual problem, there are more than two groups.  Moreover, the number of groups changes from case to case.  In my set up, I use trellis.par.set() to set line styles, colors, pch, etc.  

I would the call to xyplot() to automatically use the set options.

Thanks,
Naresh

Sent from my iPhone

> On Aug 10, 2022, at 5:40 PM, Bert Gunter <bgunter.4567 using gmail.com> wrote:
> 
> I assume you mean two line colors, not types.
> Like this?
> 
> xyplot(X ~ date, groups = interaction(name,G), data = mydf.long,
>       type = c("l", "g"), col.line = c("blue","red"))
> 
> 
> Cheers,
> Bert
> 
>> On Wed, Aug 10, 2022 at 2:12 PM Naresh Gurbuxani
>> <naresh_gurbuxani using hotmail.com> wrote:
>> 
>> Deepayan,
>> 
>> Thanks for providing a solution.  While this is close to my goal, I want one more change.  The line type (lty) should be the same for long and short.  The line type should only change according to “name” group.  So the the graph will have two line types (not four as in your solution).
>> 
>> Is it possible?
>> 
>> Thanks,
>> Narrsh
>> 
>> Sent from my iPhone
>> 
>>>> On Aug 10, 2022, at 9:37 AM, Deepayan Sarkar <deepayan.sarkar using gmail.com> wrote:
>>> 
>>> On Wed, Aug 10, 2022 at 4:53 PM Naresh Gurbuxani
>>> <naresh_gurbuxani using hotmail.com> wrote:
>>>> 
>>>> 
>>>> I want to merge two panels into one.  Is it possible to do this?
>>>> 
>>>> Thanks,
>>>> Naresh
>>>> 
>>>> library(lattice)
>>>> mydf <- data.frame(date = rep(seq.Date(as.Date("2022-08-01"), by = 1,
>>>> length.out = 10), 2), name = c(rep("Aa", 10), rep("Bb", 10)),
>>>> long = runif(20, 2, 10), short = runif(20, -10, 0))
>>>> 
>>>> # This plots data in two panels.  I want all four lines in one panel.
>>>> xyplot(long + short ~ date, groups = name, data = mydf, type = c("l",
>>>> "g"))
>>> 
>>> The "extended" formula API (with +) is really only meant as an
>>> alternative to reshape() for simple cases. In your case, you probably
>>> want something like
>>> 
>>> mydf.long = reshape(mydf, direction = "long", varying = list(c("long",
>>> "short")), v.names = "X", timevar = "G", times = c("long", "short"))
>>> 
>>> xyplot(X ~ date, groups = interaction(name, G), data = mydf.long, type
>>> = c("l", "g"))
>>> 
>>> -Deepayan
>>> 
>>>> # This does not work
>>>> # No error in R session
>>>> # Graph window says: "Error using packet 1
>>>> # argument 'subscripts' is missing, with no default"
>>>> xyplot(long ~ date, data = mydf, groups = name, type = c("l", "g"),
>>>> panel = function(x, y, ..., subscripts) {
>>>> panel.xyplot(x, y, ...)
>>>> panel.xyplot(mydf$date[subscripts], mydf$short[subscripts], ...)})
>>>> 
>>>> ______________________________________________
>>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> 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.
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.


More information about the R-help mailing list