Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the values of a log-log plot from exponential notation to numeric values in the lattice package?

Tags:

r

lattice

For instance what should I add to this expression:

xyplot(a~b, groups=abc, data=super,
       scales=list(x=list(log=TRUE),y=list(log=TRUE)), 
       panel = panel.grid)

in order to have 100 instead of 10^2?

like image 934
Attila Csordas Avatar asked Feb 21 '23 11:02

Attila Csordas


1 Answers

The latticeExtra package has a number of nifty functions for producing nicer labels for logarithmic axes. In your case, have a look at xscale.components.log10ticks.

Here's an example, taken from the help page, that shows basically what you want (although here it's the y-axis that gets the labeling you'll want on the x-axis):

 xyplot((1:200)/20 ~ (1:200)/20, type = c("p", "g"),
   scales = list(x = list(log = 2), y = list(log = 10)),
   xscale.components = xscale.components.fractions,
   yscale.components = yscale.components.log10ticks)

enter image description here


EDITED, providing an additional example to reply to comments by the original poster

library(latticeExtra)
dat <- 10^seq(-3, 5)
options(scipen=10)
options(digits=10)

xyplot(dat ~ dat, type = c("p", "g"),
   scales = list(x = list(log = 2), y = list(log = 10)),
   xscale.components = xscale.components.log10ticks,
   yscale.components = yscale.components.log10ticks)

enter image description here

like image 146
Josh O'Brien Avatar answered Feb 24 '23 13:02

Josh O'Brien