labels in lattice

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

labels in lattice

matteo
Dear all,

here is a simple problem that surely you already come across, but is giving me a big headache...

I have a dataframe like this:

set.seed(3)
mydata <- data.frame(var = rnorm(100,20,1),
                     temp = sin(sort(rep(c(1:10),10))),
                     subj = as.factor(rep(c(1:10),5)))

and I need to make a scatter plot for each subj, not a problem, but...
what i want is to replace the strips from the lattice and add a label to each plot.
I manage to do this with the following code, but I'm still not happy...

xyplot(var ~ temp | subj,
       data = mydata,
       strip=FALSE,
       panel = function(x, y,...) {
               panel.xyplot(x, y,...)
               panel.text(1,21,labels=which.packet())
               })

The last bit...where i got stacked...is how to print letters instead of numbers in each panel. I would like to call the panels a,b,c... and so on.

Any suggestions...
Many thanks
matteo
Reply | Threaded
Open this post in threaded view
|

Re: labels in lattice

David Winsemius

On Dec 14, 2011, at 11:43 AM, matteo wrote:

> set.seed(3)
> mydata <- data.frame(var = rnorm(100,20,1),
>                     temp = sin(sort(rep(c(1:10),10))),
>                     subj = as.factor(rep(c(1:10),5)))
>
> and I need to make a scatter plot for each subj, not a problem, but...
> what i want is to replace the strips from the lattice and add a  
> label to
> each plot.
> I manage to do this with the following code, but I'm still not  
> happy...
>
> xyplot(var ~ temp | subj,
>       data = mydata,
>       strip=FALSE,
>       panel = function(x, y,...) {
>               panel.xyplot(x, y,...)
>               panel.text(1,21,labels=which.packet())

Instead use the packet numer a an index into `letters`

                panel.text(1,21,labels=letters[which.packet()])

>               })

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: labels in lattice

Patrick Connolly-4
In reply to this post by matteo
On Wed, 14-Dec-2011 at 08:43AM -0800, matteo wrote:

|> Dear all,
|>
|> here is a simple problem that surely you already come across, but is giving
|> me a big headache...
|>
|> I have a dataframe like this:
|>
|> set.seed(3)
|> mydata <- data.frame(var = rnorm(100,20,1),
|>                      temp = sin(sort(rep(c(1:10),10))),
|>                      subj = as.factor(rep(c(1:10),5)))
|>
|> and I need to make a scatter plot for each subj, not a problem, but...
|> what i want is to replace the strips from the lattice and add a label to
|> each plot.
|> I manage to do this with the following code, but I'm still not happy...
|>
|> xyplot(var ~ temp | subj,
|>        data = mydata,
|>        strip=FALSE,
|>        panel = function(x, y,...) {
|>                panel.xyplot(x, y,...)
|>                panel.text(1,21,labels=which.packet())
|>                })
|>
|> The last bit...where i got stacked...is how to print letters instead of
|> numbers in each panel. I would like to call the panels a,b,c... and so on.

Make a,b,c... the levels of your subj column and lattice does it all
for you.

HTH



|>
|> Any suggestions...
|> Many thanks
|> matteo
|>
|> --
|> View this message in context: http://r.789695.n4.nabble.com/labels-in-lattice-tp4195766p4195766.html
|> Sent from the R help mailing list archive at Nabble.com.
|>
|> ______________________________________________
|> [hidden email] mailing list
|> 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.

--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.  
   ___    Patrick Connolly  
 {~._.~}                   Great minds discuss ideas    
 _( Y )_           Average minds discuss events
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)                        ..... Eleanor Roosevelt
         
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: labels in lattice

matteo
In reply to this post by David Winsemius
Thanks David and Patrick,

really appreciate tour help...

m.


Il giorno 14 Dec 2011, alle ore 18:33, David Winsemius ha scritto:

>
> On Dec 14, 2011, at 11:43 AM, matteo wrote:
>
>> set.seed(3)
>> mydata <- data.frame(var = rnorm(100,20,1),
>>                   temp = sin(sort(rep(c(1:10),10))),
>>                   subj = as.factor(rep(c(1:10),5)))
>>
>> and I need to make a scatter plot for each subj, not a problem, but...
>> what i want is to replace the strips from the lattice and add a label to
>> each plot.
>> I manage to do this with the following code, but I'm still not happy...
>>
>> xyplot(var ~ temp | subj,
>>     data = mydata,
>>     strip=FALSE,
>>     panel = function(x, y,...) {
>>             panel.xyplot(x, y,...)
>>             panel.text(1,21,labels=which.packet())
>
> Instead use the packet numer a an index into `letters`
>
>              panel.text(1,21,labels=letters[which.packet()])
>
>>             })
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>

______________________________________________
[hidden email] mailing list
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.