[R] still a problem remainingRE: Data lebals xylattice plot: RE: displaying label meeting condition (i.e. significant, i..e p value less than 005) in plot function

Felix Andrews felix at nfrac.org
Thu Mar 10 13:01:12 CET 2011


Notice that pvals is a subset of dataf so 'subscripts' can not be
applied directly to pvals. Instead you should do the subsetting inside
the panel function. e.g.
ok <- intersection(subscripts, which(dataf$p < 0.05))
with(dataf[ok,], panel.text(p, xval, name))


By the way you should include the dots (...) in your panel function
arguments and pass them on to panel.xyplot.


On Thursday, 10 March 2011, Umesh Rosyara <rosyaraur at gmail.com> wrote:
> Lattice-experts:
> Thank you for those who have responded earlier. I have not got a perfect
> solution yet but tried several ways, unless anybody really lattice killer
> steps up, I will leave it and see alternatives. Sorry to send it again.
>
>
>
> #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)
>
>
>
> #subset data
>
> pvals <- dataf[dataf$p < 0.05,]
>
>
>
> # unsuccessful commands
>
> xyplot(p ~ xvar|chr, data=dataf,
>   panel=function(x, y, subscripts){
>
>   panel.xyplot(x, y)
>
>    panel.xyplot(pvals$xvar[subscripts],pvals$p[subscripts], pch=6)
>   panel.abline(h=0.01, col="red")
>
>
>   panel.text(pvals$xvar[subscripts], pvals$p[subscripts],
> pvals$name[subscripts], col="green2")
>
>
>       }, as.table=T, subscripts=T)
>
>
>
>
>
> Best Regards
>
> Umesh R
>
>
>
>
>   _____
>
> From: Bert Gunter [mailto:gunter.berton at gene.com]
> Sent: Tuesday, March 08, 2011 12:00 AM
> To: Umesh Rosyara
> Cc: Jorge Ivan Velez; Dennis Murphy; sarah.goslee at gmail.com; R mailing list
> Subject: Re: still a problem remainingRE: [R] Data lebals xylattice plot:
> RE: displaying label meeting condition (i.e. significant, i..e p value less
> than 005) in plot function
>
>
>
> As I believe I already told you in my original reply, you have to make
> use of the subscripts argument in the panel function to subscript the
> P values etc. vector to be plotted in each panel. Something like:
> (untested)
>
>        panel = function(x, y,subscripts,...) {
>             panel.xyplot(x, y,...)
>             panel.abline(h=0.01, col="red")
>             panel.text(xv1[subscripts], p1[subscripts],
> n1[subscripts], col="green2")
>        }
>
>
> Also,in future, please send plain text email, as requested in the
> guide. Your message was in an annoying blue font in my gmail reader.
>
> Cheers,
> Bert
>
>
> On Mon, Mar 7, 2011 at 5:26 PM, Umesh Rosyara <rosyaraur at 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.berton at gene.com]
>> Sent: Sunday, March 06, 2011 10:50 AM
>> To: Umesh Rosyara
>> Cc: Jorge Ivan Velez; Dennis Murphy; sarah.goslee at 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 <rosyaraur at 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 i

-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/



More information about the R-help mailing list