Hi: This works only because all of the observations you want to label are in one panel - it is not a general solution. I used the layer() function from the latticeExtra package for this:
library(lattice) library(latticeExtra) xyplot(p ~ xvar|chr, data=dataf, panel = function(x, y, ...) { panel.xyplot(x, y, ...) panel.abline(h=0.01, col="red") }) + layer(with(pvals, panel.text(xvar, p, lab = name)), packets = 5) If you try this on the subset where p < 0.05 rather than p < 0.01, you'll see what I mean about the solution not being general. I believe a more general solution will require you to use subscripts inside your panel function for panel.text() to distribute the text labels properly across panels, because the chr in your pvals data frame needs to match the packet number (<=> panel number in this case). Dennis On Mon, Mar 7, 2011 at 5:26 PM, Umesh Rosyara <rosyar...@gmail.com> wrote: > Hi Lattice Users > > I have been working to fix this problem, still I am not able to solve > fully. I could label those names that have pvalue less than 0.01 but still > the label appears in all compoent plots eventhough those who do have the > pvalue ! How can I implement it successuflly to grouped data like mine. You > help is highly appreciated. > > #my data > name <- c(paste ("M", 1:1000, sep = "")) > xvar <- seq(1, 10000, 10) > chr <- c(rep(1,200),rep(2,200), rep(3,200), rep(4,200), rep(5,200)) > set.seed(134) > p <- rnorm(1000, 0.15,0.05) > dataf <- data.frame(name,xvar, chr, p) > dataf$chr <- as.factor(dataf$chr) > > # lattice plot: As far as I can go now ! little progress but final push > required ! > require(lattice) > pvals <- dataf[dataf$p < 0.01,] > p1 <- pvals$p > n1 <- pvals$name > xv1 <- pvals$xvar > xyplot(p ~ xvar|chr, data=dataf, > panel = function(x, y) { > panel.xyplot(x, y) > panel.abline(h=0.01, col="red") > panel.text(xv1, p1, n1, col="green2") > }) > > Thank you in advance. > > Best Regards > > Umesh R ** > ** > ** > > > ------------------------------ > *From:* Bert Gunter [mailto:gunter.ber...@gene.com] > *Sent:* Sunday, March 06, 2011 10:50 AM > *To:* Umesh Rosyara > *Cc:* Jorge Ivan Velez; Dennis Murphy; sarah.gos...@gmail.com; R mailing > list > *Subject:* Re: [R] Data lebals xylattice plot: RE: displaying label > meeting condition (i.e. significant, i..e p value less than 005) in plot > function > > This is easy to do by specifying xyplot's panel function. Assuming > only one panel -- otherwise you need to pass the subscripts arguments > to choose the values belonging to the panel -- somethings like: > > xyplot(y~x, pvals = pvals,..., ## pvals is your vector of small p > values with e.g. NA's elsewhere > panel = function(x,y, pvals,...) { > panel.xyplot(...) > panel.text((x,y, pvals,...) > } ) > > This is obviously just a sketch and will not work as written. So > please read the Help page on xyplot carefully and perhaps also > Deepayan's book on trellis graphics -- there are also undoubtedly > online resources: search on "trellis graphics tutorial" or some such. > This is not hard, but there are some details that you will need to > master,especially regarding argument passing. > > Another alternative is to use the layer() function in the latticeExtra > package instead. Consult the documentation there for details. > > Cheers, > Bert > > > > On Sun, Mar 6, 2011 at 5:17 AM, Umesh Rosyara <rosyar...@gmail.com> wrote: > > Dear Jorge, Dennis, Sarah and R-experts. > > > > Thank for helping me. As you mentioned it is difficult apply in lattice > in > > this situation. > > > > Unless, there is a possibility, I would try to use lattice. The major > reason > > toward this is- my ultimate solution might be better of in lattice as I > have > > a classificatory variable to make similar graph for each caterogory in > the > > lattice graph. Lattice cleates nice stacked xyplots. > > > > p ~ xvar | chr # require plots by the factor variable "chr" > > > > # with a classificatory variable > > name <- c(paste ("M", 1:1000, sep = "")) > > xvar <- seq(1, 10000, 10) > > chr <- c(rep(1,200),rep(2,200), rep(3,200), rep(4,200), rep(5,200)) > > set.seed(134) > > p <- rnorm(1000, 0.15,0.05) > > dataf <- data.frame(name,xvar, chr, p) > > dataf$chr <- as.factor(dataf$chr) > > > > # lattice plot: As far as I can go now ! > > require(lattice) > > xyplot(pval ~ xvar1|chr, dataf) > > > > > > Best Regards > > > > Umesh R > > > > > > > > > > _____ > > > > From: Jorge Ivan Velez > > [mailto:jorgeivanve...@gmail.com<jorgeivanve...@gmail.com> > ] > > Sent: Sunday, March 06, 2011 12:22 AM > > To: Umesh Rosyara > > Cc: R mailing list > > Subject: Re: [R] displaying label meeting condition (i.e. significant, > i..e > > p value less than 005) in plot function > > > > > > Hi Umesh, > > > > > > You can try something along the lines of: > > > > > > d <- dataf[dataf$p < 0.05, ] # p < 0.05 > > with(d, plot(xvar, p, col = 'white')) > > with(d, text(xvar, p, name, cex = .7)) > > > > HTH, > > Jorge > > > > > > > > On Sat, Mar 5, 2011 at 12:29 PM, Umesh Rosyara <> wrote: > > > > > > Dear R users, > > > > Here is my problem: > > > > # example data > > name <- c(paste ("M", 1:1000, sep = "")) > > xvar <- seq(1, 10000, 10) > > set.seed(134) > > p <- rnorm(1000, 0.15,0.05) > > dataf <- data.frame(name,xvar, p) > > plot (dataf$xvar,p) > > abline(h=0.05) > > > > # I can know which observation number is less than 0.05 > > which (dataf$p < 0.05) > > [1] 12 20 80 269 272 338 366 368 397 403 432 453 494 543 592 691 723 > 789 > > 811 > > [20] 854 891 931 955 > > > > I want to display (label) corresponding names on the plot above: > > means that 12th observation M12, 20th observation M20 and so on. Please > note > > that I have names not in numerical sequience (rather different names), > just > > provided for this example to create dataset easily. > > > > Thanks in advance > > > > Umesh R > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@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. > > > > > > > > _____ > > > > No virus found in this message. > > Checked by AVG - www.avg.com > > > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@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. > > > > > > -- > Bert Gunter > Genentech Nonclinical Biostatistics > 467-7374 > http://devo.gene.com/groups/devo/depts/ncb/home.shtml > ------------------------------ > > No virus found in this message. > Checked by AVG - www.avg.com > Version: 10.0.1204 / Virus Database: 1435/3485 - Release Date: 03/06/11 > [[alternative HTML version deleted]] ______________________________________________ R-help@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.