Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-15 Thread Deepayan Sarkar
On Mon, Jun 11, 2012 at 1:10 PM, maxbre mbres...@arpa.veneto.it wrote:
 sorry but I can't close this thread with a viable solution other than the
 following one
 (i.e. by defining an user function to add line);

 I understand that the problem is related to the fact that:
 mean(log(.)) != log(mean(.)) is
 but for some reason I can't put all that in practice inside the
 panel.abline(...)

 I would appreciate if someone can show me how (sorry but at this point I
 must give up...),

I'm not sure why this is difficult. Once you realize that your problem
was in taking mean of the log-transformed values instead of the
original values, all you need to do is transform back to the original
scale, compute mean, and transform back.

dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
scales = list(x = list(log=TRUE)),
xscale.components = xscale.components.logpower,
layout = c(5,1),
panel = function(x,y,...) {
panel.grid(h=53, v=-1, lty=dotted, col=gray)
panel.dotplot(x,y,...)
panel.abline(v = median(x), col.line=red, lty=dotted)
panel.abline(v = log10(mean(10^x)), col.line=blue, lty=dotted)
}
)

-Deepayan

 thank you all for the help


 # code start

 addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
  tcL - trellis.currentLayout()
  k-0
  for(i in 1:nrow(tcL))
    for(j in 1:ncol(tcL))
      if (tcL[i,j]  0) {
        k-k+1
        trellis.focus(panel, j, i, highlight = FALSE)
        if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else
          panel.abline(a=a, b=b, v=v, h=h, ...)
        trellis.unfocus()
      }
 }



 dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
        scales=list(x=list(log=TRUE)),
        xscale.components = xscale.components.logpower,
        layout=c(5,1),
        panel = function(x,y,...) {
          panel.grid(h=53, v=-1, lty=dotted, col=gray)
          panel.dotplot(x,y,...)
          medians - median(x)
          panel.abline(v=medians, col.line=red, lty=dotted)
          }
        )

 medie-as.vector(tapply(teq$lower_b_i,teq$site,mean))

 addLine(v=log10(medie), once=TRUE, col=blue, lty=dotted)

 # code end




 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632991.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 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.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-15 Thread maxbre
Thanks a lot, Deepayan!

What a great honour hearing from you inside this thread!

Now, at last, I understand where MY problem was 
(but please, don’t laugh – too loudly at least – and, first of all, sorry
for that!)

this was my “poor” wrong attempt (but I did not post this)

means-mean(exp(x))
panel.abline(v=log10(means), col.line=blue, lty=dotted)

instead of the correct one…

means-mean(10^x)
panel.abline(v=log10(means), col.line=blue, lty=dotted)

so, I was using the exponential function exp(), e^x, instead of 10^x 
…poor me!

And all that because I simply overlooked the fact that in

scales=list(x=list(log=TRUE))

TRUE is equivalent to 10, as clearly stated in the on-line help!!

…poor me, again!

thank you

max

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4633481.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-11 Thread maxbre
sorry but I can't close this thread with a viable solution other than the
following one 
(i.e. by defining an user function to add line);

I understand that the problem is related to the fact that: 
mean(log(.)) != log(mean(.)) is 
but for some reason I can't put all that in practice inside the
panel.abline(...)

I would appreciate if someone can show me how (sorry but at this point I
must give up...),
thank you all for the help


# code start

addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) { 
  tcL - trellis.currentLayout() 
  k-0 
  for(i in 1:nrow(tcL)) 
for(j in 1:ncol(tcL)) 
  if (tcL[i,j]  0) { 
k-k+1 
trellis.focus(panel, j, i, highlight = FALSE) 
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else 
  panel.abline(a=a, b=b, v=v, h=h, ...) 
trellis.unfocus() 
  } 
} 



dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
scales=list(x=list(log=TRUE)),
xscale.components = xscale.components.logpower,
layout=c(5,1),
panel = function(x,y,...) {
  panel.grid(h=53, v=-1, lty=dotted, col=gray)
  panel.dotplot(x,y,...)
  medians - median(x)
  panel.abline(v=medians, col.line=red, lty=dotted)
  }
)

medie-as.vector(tapply(teq$lower_b_i,teq$site,mean))

addLine(v=log10(medie), once=TRUE, col=blue, lty=dotted) 

# code end




--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632991.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-08 Thread maxbre
thanks david,
yes, you are right PART of the confusion is because of what you mentioned
(sorry for that) but going back to my own data this is JUST PART of the
problem…

...see my reproducible example

teq-structure(list(site = structure(c(4L, 2L, 2L, 4L, 2L, 4L, 4L, 
3L, 1L, 3L, 1L, 1L, 3L, 4L, 5L, 4L, 3L, 1L, 3L, 1L, 4L, 4L, 2L, 
4L, 4L, 2L, 1L, 3L, 4L, 4L, 2L, 4L, 4L, 2L, 4L, 4L, 2L, 4L, 4L, 
2L, 4L, 2L, 4L, 2L, 4L, 2L, 4L, 2L, 2L, 2L, 2L, 4L), .Label = c(A, 
B, C, D, E), class = factor), lower_b_i = c(0.302, 
0.956, 0.72, 1.21, 0.887, 0.728, 1.294, 20.493, 0.902, 0.031, 
0.468, 2.318, 4.795, 89.581, 4.59, 3.366, 32.786, 5.506, 61.038, 
1.485, 42.25, 31.279, 21.375, 96.62, 36.099, 30.173, 0.532, 1.005, 
0.697, 6.248, 2.121, 0.576, 0.335, 0.442, 22.704, 18.244, 16.53, 
626.664, 42.714, 59.87, 9.983, 110.158, 4.763, 3.363, 2.608, 
2.41, 23.904, 73.281, 3618.353, 109.663, 21.797, 3.39), date_sampl_time_recs
= structure(c(11L, 
10L, 9L, 8L, 12L, 12L, 13L, 7L, 6L, 14L, 14L, 4L, 3L, 5L, 2L, 
1L, 18L, 19L, 24L, 23L, 17L, 15L, 16L, 20L, 21L, 22L, 26L, 25L, 
29L, 28L, 27L, 32L, 31L, 30L, 34L, 33L, 33L, 35L, 36L, 37L, 38L, 
39L, 40L, 41L, 42L, 43L, 46L, 47L, 48L, 49L, 45L, 44L), .Label =
c(2008-07-15, 2 h, 16/17, 
2008-07-16, 2 h, 14/17, 2008-12-03, 4 h, 13/17, 2008-12-03, 4 h,
15/17, 
2009-01-29, 24 h, 0/17, 2009-03-17, 24 h, 14/17, 2009-03-17, 24 h,
8/17, 
2009-04-17, 135 h, 13/17, 2009-04-20, 96 h, 14/17, 2009-04-21, 24 h,
13/17, 
2009-04-21, 24 h, 14/17, 2009-07-17, 168 h, 13/17, 2009-07-21, 24 h,
12/17, 
2009-08-18, 24 h, 16/17, 2009-10-27, 168 h, 3/17, 2009-10-27, 168 h,
5/17, 
2009-11-01, 24 h, 4/17, 2009-12-15, 24 h, 6/17, 2009-12-15, 24 h,
9/17, 
2010-01-05, 12 h, 3/17, 2010-01-15, 168 h, 3/17, 2010-01-15, 168 h,
5/17, 
2010-01-19, 24 h, 12/17, 2010-01-19, 24 h, 2/17, 2010-03-30, 24 h,
13/17, 
2010-03-30, 24 h, 14/17, 2010-04-22, 168 h, 11/17, 2010-04-22, 168 h,
9/17, 
2010-04-22, 24 h, 14/17, 2010-07-22, 168 h, 14/17, 2010-07-22, 168 h,
15/17, 
2010-07-22, 24 h, 15/17, 2010-10-26, 168 h, 7/17, 2010-10-26, 24 h,
8/17, 
2011-01-05, 12 h, 0/17, 2011-01-11, 168 h, 0/17, 2011-01-19, 168 h,
0/17, 
2011-03-15, 168 h, 2/17, 2011-03-23, 168 h, 0/17, 2011-05-10, 168 h,
5/17, 
2011-05-18, 168 h, 7/17, 2011-07-05, 168 h, 7/17, 2011-07-13, 168 h,
7/17, 
2011-09-13, 168 h, 6/17, 2011-09-21, 168 h, 1/17, 2011-11-08, 168 h,
0/17, 
2011-11-16, 168 h, 0/17, 2012-01-05, 12 h, 1/17, 2012-01-09, 12 h,
2/17
), class = factor)), .Names = c(site, lower_b_i,
date_sampl_time_recs
), class = data.frame, row.names = c(NA, -52L))

...and my code

dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
scales=list(x=list(log=TRUE)),
xscale.components = xscale.components.logpower,
layout=c(5,1),
panel = function(x,y,...) {
  panel.grid(h=53, v=-1, lty=dotted, col=gray)
  panel.dotplot(x,y,...)
  medians - median(x)
  panel.abline(v=medians, col.line=red, lty=dotted)
  means-mean(x)
  panel.abline(v=means, col.line=blue, lty=dotted)
}
)

attach(teq)

#check median values
tapply(lower_b_i,site,median)
#check mean values
tapply(lower_b_i,site,mean)

detach(teq)


...and now the question is why the plotting of means (but not medians) is
wrong (check against results of tapply)?

thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632760.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-08 Thread David Winsemius


On Jun 8, 2012, at 3:52 AM, maxbre wrote:


thanks david,
yes, you are right PART of the confusion is because of what you  
mentioned
(sorry for that) but going back to my own data this is JUST PART of  
the

problem…

...see my reproducible example

teq-structure(list(site = structure(c(4L, 2L, 2L, 4L, 2L, 4L, 4L,
3L, 1L, 3L, 1L, 1L, 3L, 4L, 5L, 4L, 3L, 1L, 3L, 1L, 4L, 4L, 2L,
4L, 4L, 2L, 1L, 3L, 4L, 4L, 2L, 4L, 4L, 2L, 4L, 4L, 2L, 4L, 4L,
2L, 4L, 2L, 4L, 2L, 4L, 2L, 4L, 2L, 2L, 2L, 2L, 4L), .Label = c(A,
B, C, D, E), class = factor), lower_b_i = c(0.302,
0.956, 0.72, 1.21, 0.887, 0.728, 1.294, 20.493, 0.902, 0.031,
0.468, 2.318, 4.795, 89.581, 4.59, 3.366, 32.786, 5.506, 61.038,
1.485, 42.25, 31.279, 21.375, 96.62, 36.099, 30.173, 0.532, 1.005,
0.697, 6.248, 2.121, 0.576, 0.335, 0.442, 22.704, 18.244, 16.53,
626.664, 42.714, 59.87, 9.983, 110.158, 4.763, 3.363, 2.608,
2.41, 23.904, 73.281, 3618.353, 109.663, 21.797, 3.39),  
date_sampl_time_recs

= structure(c(11L,
10L, 9L, 8L, 12L, 12L, 13L, 7L, 6L, 14L, 14L, 4L, 3L, 5L, 2L,
1L, 18L, 19L, 24L, 23L, 17L, 15L, 16L, 20L, 21L, 22L, 26L, 25L,
29L, 28L, 27L, 32L, 31L, 30L, 34L, 33L, 33L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 46L, 47L, 48L, 49L, 45L, 44L), .Label =
c(2008-07-15, 2 h, 16/17,
2008-07-16, 2 h, 14/17, 2008-12-03, 4 h, 13/17, 2008-12-03, 4 h,
15/17,
2009-01-29, 24 h, 0/17, 2009-03-17, 24 h, 14/17, 2009-03-17, 24  
h,

8/17,
2009-04-17, 135 h, 13/17, 2009-04-20, 96 h, 14/17, 2009-04-21,  
24 h,

13/17,
2009-04-21, 24 h, 14/17, 2009-07-17, 168 h, 13/17, 2009-07-21,  
24 h,

12/17,
2009-08-18, 24 h, 16/17, 2009-10-27, 168 h, 3/17, 2009-10-27,  
168 h,

5/17,
2009-11-01, 24 h, 4/17, 2009-12-15, 24 h, 6/17, 2009-12-15, 24 h,
9/17,
2010-01-05, 12 h, 3/17, 2010-01-15, 168 h, 3/17, 2010-01-15,  
168 h,

5/17,
2010-01-19, 24 h, 12/17, 2010-01-19, 24 h, 2/17, 2010-03-30, 24  
h,

13/17,
2010-03-30, 24 h, 14/17, 2010-04-22, 168 h, 11/17, 2010-04-22,  
168 h,

9/17,
2010-04-22, 24 h, 14/17, 2010-07-22, 168 h, 14/17, 2010-07-22,  
168 h,

15/17,
2010-07-22, 24 h, 15/17, 2010-10-26, 168 h, 7/17, 2010-10-26,  
24 h,

8/17,
2011-01-05, 12 h, 0/17, 2011-01-11, 168 h, 0/17, 2011-01-19,  
168 h,

0/17,
2011-03-15, 168 h, 2/17, 2011-03-23, 168 h, 0/17, 2011-05-10,  
168 h,

5/17,
2011-05-18, 168 h, 7/17, 2011-07-05, 168 h, 7/17, 2011-07-13,  
168 h,

7/17,
2011-09-13, 168 h, 6/17, 2011-09-21, 168 h, 1/17, 2011-11-08,  
168 h,

0/17,
2011-11-16, 168 h, 0/17, 2012-01-05, 12 h, 1/17, 2012-01-09, 12  
h,

2/17
), class = factor)), .Names = c(site, lower_b_i,
date_sampl_time_recs
), class = data.frame, row.names = c(NA, -52L))

...and my code

dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
   scales=list(x=list(log=TRUE)),
   xscale.components = xscale.components.logpower,
   layout=c(5,1),
   panel = function(x,y,...) {
 panel.grid(h=53, v=-1, lty=dotted, col=gray)
 panel.dotplot(x,y,...)
 medians - median(x)
 panel.abline(v=medians, col.line=red, lty=dotted)
 means-mean(x)
 panel.abline(v=means, col.line=blue, lty=dotted)
   }
   )

attach(teq)

#check median values
tapply(lower_b_i,site,median)

 tapply(lower_b_i,site,median)
  A   B   C   D   E
 1.1935 18.9525 12.6440  6.2480  4.5900
 #check mean values
 tapply(lower_b_i,site,mean)
A B C D E
  1.86850 254.50619  20.02467  46.32865   4.59000


#check mean values

 #check mean values
 tapply(lower_b_i,site,mean)
A B C D E
  1.86850 254.50619  20.02467  46.32865   4.59000

tapply(lower_b_i,site,mean)

detach(teq)


...and now the question is why the plotting of means (but not  
medians) is

wrong (check against results of tapply)?



This is the context that you failed to include:

Part of the confusion may be that you have reversed the colors for  
mean and median in two different examples. The other confusion may  
be that mean(log(.)) != log(mean(.))


I do not see reference to which of those sources of confusion you  
believe you have adequately addressed. I suspect you may have only  
read the first sentence.


with(teq, tapply(lower_b_i,site,function(x) exp(mean(log(x) )) )  )
A B C D E
 1.273034 12.084054  4.277616  7.151560  4.59



--

David Winsemius, MD
West Hartford, CT

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread maxbre
thanks ilai

sorry, I mixed up a little: I was thinking to medians of each panel but
instead I was trying to plot medians for each variety (what an awful chart,
indeed!) 
thanks for your solution (medians for each panel), it works perfectly, as
usual...

cheers

max

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632641.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread maxbre
...and what if I need to plot another vertical line for showing also the
means for each panel?
by simply adding another call to panel.abline () seems not producing a
correct result for each panel

# medians and means for each panel:
dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
   panel.dotplot(x,y,...)
   median.values - median(x)
   panel.abline(v=median.values, col.line=red)
   mean.values - mean(x)
   panel.abline(v=mean.values, col.line=red)
})

In the dataset I'm currently working on (which is not the above mentioned
example) I've got a wrong plottting of the means for each panel, what I'm
missing?

thanks
 



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632678.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread K. Elo

Hi!

I recently posted a similar question (entitled Adding mean line to a 
lattice density plot). Have not got any usable solution forcing my to 
fall back to the use of the normal 'plot' function. The problem was the 
same as yours: using panel.abline simply did not work, the position of 
the mean line was incorrect. I have posted a workaround (based on plot), 
please see my earlier posting.


HTH,
Kimmo

07.06.2012 15:37, maxbre wrote:

...and what if I need to plot another vertical line for showing also the
means for each panel?
by simply adding another call to panel.abline () seems not producing a
correct result for each panel

# medians and means for each panel:
dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(x,y,...) {
panel.dotplot(x,y,...)
median.values- median(x)
panel.abline(v=median.values, col.line=red)
mean.values- mean(x)
panel.abline(v=mean.values, col.line=red)
})

In the dataset I'm currently working on (which is not the above mentioned
example) I've got a wrong plottting of the means for each panel, what I'm
missing?

thanks


__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread maxbre
thanks kimmo

I managed to get the desired result by first plotting the medians and then
adding the means through the user defind function posted in thread you
mentioned (here it is
http://r.789695.n4.nabble.com/Adding-mean-line-to-a-lattice-density-plot-td4455770.html#a4456502)

# start

dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(x,y,...) {
  panel.dotplot(x,y,...)
  median.values - median(x)
  panel.abline(v=median.values, col.line=red) 
  }) 

addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) { 
  tcL - trellis.currentLayout() 
  k-0 
  for(i in 1:nrow(tcL)) 
for(j in 1:ncol(tcL)) 
  if (tcL[i,j]  0) { 
k-k+1 
trellis.focus(panel, j, i, highlight = FALSE) 
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else 
  panel.abline(a=a, b=b, v=v, h=h, ...) 
trellis.unfocus() 
  } 
}

mean.values-tapply(barley$yield, barley$site, mean)

addLine(v=log10(mean.values), once=TRUE, col=blue, lty=dotted)

# end

but back to my previous question I still not understand why the plot of
medians is working fine BUT NOT of the means (apparently messing up panel
positions and also values): no clue for this!

I've been trying also with the use of layout() in latticeExtra but without
results...

anyone can clarify me these (strange for me) issues?

max
 



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632692.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread David Winsemius


On Jun 7, 2012, at 10:23 AM, maxbre wrote:


thanks kimmo

I managed to get the desired result by first plotting the medians  
and then

adding the means through the user defind function posted in thread you
mentioned (here it is
http://r.789695.n4.nabble.com/Adding-mean-line-to-a-lattice-density-plot-td4455770.html#a4456502)

# start

dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
 panel.dotplot(x,y,...)
 median.values - median(x)
 panel.abline(v=median.values, col.line=red)
 })

addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
 tcL - trellis.currentLayout()
 k-0
 for(i in 1:nrow(tcL))
   for(j in 1:ncol(tcL))
 if (tcL[i,j]  0) {
   k-k+1
   trellis.focus(panel, j, i, highlight = FALSE)
   if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...)  
else

 panel.abline(a=a, b=b, v=v, h=h, ...)
   trellis.unfocus()
 }
}

mean.values-tapply(barley$yield, barley$site, mean)

addLine(v=log10(mean.values), once=TRUE, col=blue, lty=dotted)

# end

but back to my previous question I still not understand why the plot  
of
medians is working fine BUT NOT of the means (apparently messing up  
panel

positions and also values): no clue for this!


Can you explain what you mean by messing up panel positions and also  
values? When I execute this code with and without the two code lines  
for mean vertical lines I get expected results:


dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
 panel.dotplot(x,y,...)
 mean.values - mean(x)   #omitted in second run
 panel.abline(v=mean.values, col.line=red)   #omitted in  
second run

 median.values - median(x)
 panel.abline(v=median.values, col.line=blue)
 })

---
David.

sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  splines   stats grDevices utils datasets   
graphics  methods   base


other attached packages:
 [1] lme4_0.999375-42 Matrix_1.0-5 ggplot2_0.9.0 
forecast_3.19
 [5] RcppArmadillo_0.2.36 Rcpp_0.9.10  fracdiff_1.4-0
tseries_0.10-27
 [9] quadprog_1.5-4   zoo_1.7-6MASS_7.3-17   
circular_0.4-3
[13] boot_1.3-4   rms_3.5-0Hmisc_3.9-2   
survival_2.36-12

[17] sos_1.3-1brew_1.0-6   lattice_0.20-6

loaded via a namespace (and not attached):
 [1] cluster_1.14.2 colorspace_1.1-0   dichromat_1.2-4 
digest_0.5.1   fortunes_1.4-2
 [6] grid_2.14.2memoise_0.1munsell_0.3 
nlme_3.1-103   plyr_1.7.1
[11] proto_0.3-9.2  RColorBrewer_1.0-5 reshape2_1.2.1  
rgl_0.92.861   scales_0.2.0

[16] stats4_2.14.2  stringr_0.6tools_2.14.2   vcd_1.2-12




I've been trying also with the use of layout() in latticeExtra but  
without

results...

anyone can clarify me these (strange for me) issues?

max




--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632692.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


David Winsemius, MD
West Hartford, CT

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread maxbre
a new session of R with the following sessionInfo()

R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252   
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C  
[5] LC_TIME=Italian_Italy.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods  
[7] base 

other attached packages:
[1] latticeExtra_0.6-19 RColorBrewer_1.0-5  lattice_0.20-6 

loaded via a namespace (and not attached):
[1] grid_2.15.0  tools_2.15.0


this is the code I run

#start

library(lattice); library(latticeExtra)


#example with user function

addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) { 
  tcL - trellis.currentLayout() 
  k-0 
  for(i in 1:nrow(tcL)) 
for(j in 1:ncol(tcL)) 
  if (tcL[i,j]  0) { 
k-k+1 
trellis.focus(panel, j, i, highlight = FALSE) 
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else 
  panel.abline(a=a, b=b, v=v, h=h, ...) 
trellis.unfocus() 
  } 
}


dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(x,y,...) {
  panel.dotplot(x,y,...)
  median.values - median(x)
  panel.abline(v=median.values, col.line=red) 
}) 

mean.values-tapply(barley$yield, barley$site, mean)

addLine(v=log10(mean.values), once=TRUE, col=blue)


# example with panel.abline

dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(x,y,...) {
  panel.dotplot(x,y,...)
  mean.values - mean(x)   #omitted in second run
  panel.abline(v=mean.values, col.line=red)   #omitted in second
run
  median.values - median(x)
  panel.abline(v=median.values, col.line=blue)
})

#end

this are the two different results I’ve got:
 
example with user defined function 
http://r.789695.n4.nabble.com/file/n4632706/example_with_user_function.png 

example with panel.abline
http://r.789695.n4.nabble.com/file/n4632706/example_with_panel_abline.png 

and now I’m really confused of what I’m doing and seeing…



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632706.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-07 Thread David Winsemius


On Jun 7, 2012, at 11:34 AM, maxbre wrote:


a new session of R with the following sessionInfo()




Part of the confusion may be that you have reversed the colors for  
mean and median in two different examples. The other confusion may be  
that mean(log(.)) != log(mean(.))




this is the code I run

#start

library(lattice); library(latticeExtra)


#example with user function

addLine- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
 tcL - trellis.currentLayout()
 k-0
 for(i in 1:nrow(tcL))
   for(j in 1:ncol(tcL))
 if (tcL[i,j]  0) {
   k-k+1
   trellis.focus(panel, j, i, highlight = FALSE)
   if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...)  
else

 panel.abline(a=a, b=b, v=v, h=h, ...)
   trellis.unfocus()
 }
}


dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
 panel.dotplot(x,y,...)
 median.values - median(x)
 panel.abline(v=median.values, col.line=red)
   })

mean.values-tapply(barley$yield, barley$site, mean)

addLine(v=log10(mean.values), once=TRUE, col=blue)


# example with panel.abline

dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
 panel.dotplot(x,y,...)
 mean.values - mean(x)   #omitted in second run
 panel.abline(v=mean.values, col.line=red)   #omitted in  
second

run
 median.values - median(x)
 panel.abline(v=median.values, col.line=blue)
   })

#end

this are the two different results I’ve got:

example with user defined function
http://r.789695.n4.nabble.com/file/n4632706/example_with_user_function.png

example with panel.abline
http://r.789695.n4.nabble.com/file/n4632706/example_with_panel_abline.png

and now I’m really confused of what I’m doing and seeing…



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632706.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


David Winsemius, MD
West Hartford, CT

__
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.


[R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-06 Thread maxbre
by considering this example from barley dataset

#code start

dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(...) {
panel.dotplot(...)
#median.values - tapply(x, y, median)# medians for each
variety
#panel.abline(v=median.values, col.line=red)# but this is not
working!
#panel.curve(...) # how to properly
set this?
}
)

#code end

I want to plot as a reference vertical line the medians for each panel

I’ve been reading in 
https://stat.ethz.ch/pipermail/r-help/2009-January/185384.html 
that it’s not possible with panel.abline() and it’s probably necessary to
use panel.curve() instead; unfortunately I can’t figure (manage) how, any
help for this?

thank you




--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to add a vertical line for each panel in a lattice dotplot with log scale?

2012-06-06 Thread ilai
You say median for each panel but tapply gets medians for each variety
(chartjunk IMHO). Regardless, *this case* has nothing to do with
panel.abline. Add print(median.values) to your panel function would have
hinted as to the missing piece.

# medians for each panel:
dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
   panel.dotplot(x,y,...)
   median.values - median(x)
   panel.abline(v=median.values, col.line=red)
})

# medians for each variety
 dotplot(variety ~ yield | site, data = barley,
   scales=list(x=list(log=TRUE)),
   layout = c(1,6),
   panel = function(x,y,...) {
   panel.dotplot(x,y,...)
   median.values - tapply(x, y, median)
panel.abline(v=median.values, col.line=red)
   }
   )

Cheers

On Wed, Jun 6, 2012 at 6:10 AM, maxbre mbres...@arpa.veneto.it wrote:

 by considering this example from barley dataset

 #code start

 dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(...) {
panel.dotplot(...)
#median.values - tapply(x, y, median)# medians for each
 variety
#panel.abline(v=median.values, col.line=red)# but this is not
 working!
#panel.curve(...) # how to properly
 set this?
}
)

 #code end

 I want to plot as a reference vertical line the medians for each panel

 I’ve been reading in
 https://stat.ethz.ch/pipermail/r-help/2009-January/185384.html
 that it’s not possible with panel.abline() and it’s probably necessary to
 use panel.curve() instead; unfortunately I can’t figure (manage) how, any
 help for this?

 thank you




 --
 View this message in context:
 http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 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.


[[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.