Reputation: 13335
How can I put my axis labels in a convenient format in lattice?
require(stats)
xyplot(lat*1000000 ~ long, data = quakes)
gives me y-labels like -3.5e+0.7
. I would want lattice to write the whole number.
(maybe it is easy, but I can't find a solution.)
Thank you in advance!
Upvotes: 2
Views: 2409
Reputation: 263362
There are a couple of "global options" that might affect how values are printed. In this case scipen
is the one you want to move:
old_op <- options(scipen=10)
xyplot(lat*1000000 ~ long, data = quakes)
options(old_op)
# probably better to restore it so the rest of you session is more "normal"
Upvotes: 2
Reputation: 121077
Create your own labels and pass them to the scales
argument.
y_at <- pretty(quakes$lat*1e6)
y_labels <- formatC(y_at, digits = 0, format = "f")
xyplot(
lat*1000000 ~ long,
data = quakes,
scales = list(
y = list(
at = y_at,
labels = y_labels
)
)
)
For the formatting step, there are lots of alternatives to formatC
. Take a look at format
, prettyNum
and sprintf
to get you started.
If you want to do this with dates, then note that scales
accepts a format
argument for that purpose.
Upvotes: 9