[R] scientific vs. fixed notation in xyplot()

array chip arrayprofile at yahoo.com
Tue Sep 28 02:28:22 CEST 2010


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

> 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:

> Try this:
> 
>  xyplot(1:10~1:10, scales=list(log = T, labels = round(log(1:10), 4)))
> 
> 
> On Mon, Sep 27, 2010 at 4:10 PM, array chip <arrayprofile at yahoo.com> wrote:
> 
>> 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
> 
> --Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
> 
>     [[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.

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.







More information about the R-help mailing list