Skip to content

scientific vs. fixed notation in xyplot()

8 messages · Henrique Dallazuanna, Don McKenzie, array chip +1 more

#
Hi I am using xyplot() to plot on the log scale by using scale=list(log=T) 
argument. For example:

xyplot(1:10~1:10, scales=list(log=T))

But the axis labels are printed as scientific notation (10^0.0, etc), instead of 
fixed notation. How can I change that to fixed notation?

options(scipen=4) doesn't work on xyplot()

Thanks

John
#
This is quite elegant (thanks) and brings up a problem I could not  
solve awhile back, although Dr. Sarkar did his best to help.
How do I do the same thing in a panel plot?

e.g., toy example

temp.df <- data.frame(X=seq(1,100,by=1),Y=seq(1,50.5,by=.5),class=rep 
(c("A","B"),each=50))
xyplot(Y ~ X | class,data=temp.df,scales=list(x=round(log(1:100),  
4),y=round(log(1:50.5), 4),log=T))

gives me the right points on the page but still gives axis labels in  
scientific notation.

If I try to specify "labels" as a list I get an error message

 > xyplot(Y ~ X | class,data=temp.df,scales=list(log = T, labels =  
list(x=round(log(1:100), 4),y=round(log(1:50.5), 4))))

Error in construct.scales(log = TRUE, labels = list(x = c(0, 0.6931,  
1.0986,  :
   the at and labels components of scales may not be lists when  
relation = same

Syntax problem in this last command?

Thanks
On 27-Sep-10, at 12:16 PM, Henrique Dallazuanna wrote:

            
Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

desk: 206-732-7824
cell: 206-321-5966
dmck at uw.edu
donaldmckenzie at fs.fed.us
#
Hi, I found an old thread which refered to 2 examples (Fig 8.4 & Fig 8.5) from 
Dr. Sarkar's lattice book that address this problem using "xscale.components" 
and "yscale.components":

http://lmdvr.r-forge.r-project.org/figures/figures.html

I am able to change the label of x-axis, but still can't change the y-axis 
label. I think it's straight forward, but can't figure out what I am missing in 
the code, Can anyone suggest?

logTicks <- function (lim, loc = c(1, 5)) { 
    ii <- floor(log10(range(lim))) + c(-1, 2) 
    main <- 10^(ii[1]:ii[2]) 
    r <- as.numeric(outer(loc, main, "*")) 
    r[lim[1] <= r & r <= lim[2]] } 


xscale.components.log10 <- function(lim, ...) { 
    ans <- xscale.components.default(lim = lim, ...)
    tick.at <- logTicks(10^lim,loc=1)
    ans$bottom$ticks$at <- log(tick.at, 10)
    ans$bottom$labels$at <- log(tick.at, 10)
    ans$bottom$labels$labels <- as.character(tick.at)
    ans } 

yscale.components.log10 <- function(lim, ...) { 
    ans <- yscale.components.default(lim = lim, ...)
    tick.at <- logTicks(10^lim,loc=1)
    ans$bottom$ticks$at <- log(tick.at, 10)
    ans$bottom$labels$at <- log(tick.at, 10)
    ans$bottom$labels$labels <- as.character(tick.at)
    ans } 

xyplot(1:10000~1:10000, scales=list(log=T),xscale.components = 
xscale.components.log10,yscale.components = yscale.components.log10)

Any suggestions?

Thanks

John







----- Original Message ----
From: Don McKenzie <dmck at u.washington.edu>
To: Henrique Dallazuanna <wwwhsd at gmail.com>
Cc: R-help Forum <r-help at r-project.org>
Sent: Mon, September 27, 2010 1:00:04 PM
Subject: Re: [R] scientific vs. fixed notation in xyplot()

This is quite elegant (thanks) and brings up a problem I could not solve awhile 
back, although Dr. Sarkar did his best to help.
How do I do the same thing in a panel plot?

e.g., toy example

temp.df <- 
data.frame(X=seq(1,100,by=1),Y=seq(1,50.5,by=.5),class=rep(c("A","B"),each=50))
xyplot(Y ~ X | class,data=temp.df,scales=list(x=round(log(1:100), 
4),y=round(log(1:50.5), 4),log=T))

gives me the right points on the page but still gives axis labels in scientific 
notation.

If I try to specify "labels" as a list I get an error message
Error in construct.scales(log = TRUE, labels = list(x = c(0, 0.6931, 1.0986,  :
  the at and labels components of scales may not be lists when relation = same

Syntax problem in this last command?

Thanks
On 27-Sep-10, at 12:16 PM, Henrique Dallazuanna wrote:

            
Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

desk: 206-732-7824
cell: 206-321-5966
dmck at uw.edu
donaldmckenzie at fs.fed.us

______________________________________________
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.
#
I found where the problem is with y-axis, the yscale.components.log10 should be

yscale.components.log10 <- function(lim, ...) { 
    ans <- yscale.components.default(lim = lim, ...)
    tick.at <- logTicks(10^lim,loc=1)
    ans$left$ticks$at <- log(tick.at, 10)
    ans$left$labels$at <- log(tick.at, 10)
    ans$left$labels$labels <- as.character(tick.at)
    ans } 






----- Original Message ----
From: array chip <arrayprofile at yahoo.com>
To: Don McKenzie <dmck at u.washington.edu>; Henrique Dallazuanna 
<wwwhsd at gmail.com>
Cc: R-help Forum <r-help at r-project.org>
Sent: Mon, September 27, 2010 3:09:20 PM
Subject: Re: [R] scientific vs. fixed notation in xyplot()

Hi, I found an old thread which refered to 2 examples (Fig 8.4 & Fig 8.5) from 
Dr. Sarkar's lattice book that address this problem using "xscale.components" 
and "yscale.components":

http://lmdvr.r-forge.r-project.org/figures/figures.html

I am able to change the label of x-axis, but still can't change the y-axis 
label. I think it's straight forward, but can't figure out what I am missing in 
the code, Can anyone suggest?

logTicks <- function (lim, loc = c(1, 5)) { 
    ii <- floor(log10(range(lim))) + c(-1, 2) 
    main <- 10^(ii[1]:ii[2]) 
    r <- as.numeric(outer(loc, main, "*")) 
    r[lim[1] <= r & r <= lim[2]] } 


xscale.components.log10 <- function(lim, ...) { 
    ans <- xscale.components.default(lim = lim, ...)
    tick.at <- logTicks(10^lim,loc=1)
    ans$bottom$ticks$at <- log(tick.at, 10)
    ans$bottom$labels$at <- log(tick.at, 10)
    ans$bottom$labels$labels <- as.character(tick.at)
    ans } 

yscale.components.log10 <- function(lim, ...) { 
    ans <- yscale.components.default(lim = lim, ...)
    tick.at <- logTicks(10^lim,loc=1)
    ans$bottom$ticks$at <- log(tick.at, 10)
    ans$bottom$labels$at <- log(tick.at, 10)
    ans$bottom$labels$labels <- as.character(tick.at)
    ans } 

xyplot(1:10000~1:10000, scales=list(log=T),xscale.components = 
xscale.components.log10,yscale.components = yscale.components.log10)

Any suggestions?

Thanks

John







----- Original Message ----
From: Don McKenzie <dmck at u.washington.edu>
To: Henrique Dallazuanna <wwwhsd at gmail.com>
Cc: R-help Forum <r-help at r-project.org>
Sent: Mon, September 27, 2010 1:00:04 PM
Subject: Re: [R] scientific vs. fixed notation in xyplot()

This is quite elegant (thanks) and brings up a problem I could not solve awhile 
back, although Dr. Sarkar did his best to help.
How do I do the same thing in a panel plot?

e.g., toy example

temp.df <- 
data.frame(X=seq(1,100,by=1),Y=seq(1,50.5,by=.5),class=rep(c("A","B"),each=50))
xyplot(Y ~ X | class,data=temp.df,scales=list(x=round(log(1:100), 
4),y=round(log(1:50.5), 4),log=T))

gives me the right points on the page but still gives axis labels in scientific 
notation.

If I try to specify "labels" as a list I get an error message
Error in construct.scales(log = TRUE, labels = list(x = c(0, 0.6931, 1.0986,  :
  the at and labels components of scales may not be lists when relation = same

Syntax problem in this last command?

Thanks
On 27-Sep-10, at 12:16 PM, Henrique Dallazuanna wrote:

            
Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

desk: 206-732-7824
cell: 206-321-5966
dmck at uw.edu
donaldmckenzie at fs.fed.us

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





______________________________________________
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.
#
On Mon, Sep 27, 2010 at 5:28 PM, array chip <arrayprofile at yahoo.com> wrote:
A few such functions are now available in latticeExtra. E.g.,

library(latticeExtra)

xyplot(1:10~1:10, scales=list(log=T),
       yscale.components = yscale.components.log10.3)

xyplot(1:10~1:10, scales=list(log=T),
       yscale.components = yscale.components.log10ticks)

-Deepayan
#
Thank you Dr. Sarkar. yscale.components.log10.3 is pretty good choice.

John



----- Original Message ----
From: Deepayan Sarkar <deepayan.sarkar at gmail.com>
To: array chip <arrayprofile at yahoo.com>
Cc: Don McKenzie <dmck at u.washington.edu>; Henrique Dallazuanna 
<wwwhsd at gmail.com>; R-help Forum <r-help at r-project.org>
Sent: Mon, September 27, 2010 8:07:15 PM
Subject: Re: [R] scientific vs. fixed notation in xyplot()
On Mon, Sep 27, 2010 at 5:28 PM, array chip <arrayprofile at yahoo.com> wrote:
be
A few such functions are now available in latticeExtra. E.g.,

library(latticeExtra)

xyplot(1:10~1:10, scales=list(log=T),
? ? ? yscale.components = yscale.components.log10.3)

xyplot(1:10~1:10, scales=list(log=T),
? ? ? yscale.components = yscale.components.log10ticks)

-Deepayan
in
awhile
data.frame(X=seq(1,100,by=1),Y=seq(1,50.5,by=.5),class=rep(c("A","B"),each=50))
scientific
?: