[R] Label individual points in lattice by and ID

Felix Andrews felix at nfrac.org
Mon Dec 7 10:18:30 CET 2009


If you want to plot each point as the text of its ID, use a panel function:
panel = function(x, y, groups, subscripts, ...) panel.text(x, y,
groups[subscripts])

If you want to add labels interactively to selected points:
xyplot(y~x | f1 + f2, groups=ID,dat)
## repeat for each panel:
trellis.focus(); panel.identify(); trellis.unfocus()


2009/12/7 Pat Schmitz <pschmitz at illinois.edu>:
> Sorry.  My previous code didn't quite display my problem correctly.  To make
> my point more clear, I want to use my "groups" as the label for the point,
> or rather the point itself.  The key becomes illegible with many groups.
>
> x<-as.factor(1:5)
> y<-rnorm(1:10)
> f1<-c("a","b")
> f2<-c("x","y")
>
> dat<-expand.grid(x=x, y=y, f1=f1, f2=f2)
> dat$ID <- 1:dim(dat)[1]
>
> xyplot(y~x | f1 + f2, groups=ID,dat)
>
> xyplot(y~x | f1 + f2, groups=ID,auto.key=TRUE,dat)  # more accurate rep of
> problem with key
>
>
> Thanks
> Pat
>
>
> On Sun, Dec 6, 2009 at 9:58 PM, Pat Schmitz <pschmitz at illinois.edu> wrote:
>
>> I am using a plot to inspect data points, and I would like to identify each
>> point with respect to an ID. At issue is that I am producing a faceted plot
>> with many IDs (96) and the key is far to large to accurately identify points
>> by color.
>>
>> 1) Can you direct me on labeling or printing data points by an ID instead
>> of a point, as in "ID" in this toy example
>> 2) alternately is there method for printing a key for each panel which
>> shows only those IDs which appear in the panel at hand?
>>
>> x<-as.factor(1:5)
>> y<-rnorm(1:10)
>> ID<-1:5
>> f1<-c("a","b")
>> f2<-c("x","y")
>>
>> dat<-expand.grid(x=x, y=y, id=ID, f1=f1, f2=f2)
>>
>> xyplot(y~x | f1 + f2, dat)
>>
>>
>>
>> Thanks
>> Pat
>>
>> --
>> Patrick Schmitz
>> Graduate Student
>> Plant Biology
>> 1206 West Gregory Drive
>> RM 1500
>>
>
>
>
> --
> Patrick Schmitz
> Graduate Student
> Plant Biology
> 1206 West Gregory Drive
> RM 1500
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/




More information about the R-help mailing list