[R] dotplot & lattice problems: y axis values and bg color output in jpg
deepayan at stat.wisc.edu
Sat Oct 23 01:26:27 CEST 2004
On Friday 22 October 2004 17:16, Paul Johnson wrote:
> I have a linux system with Fedora Core 2 and R-2.0.
> I was comparing plots made with plot() and dotplot() and discovered a
> problem. Although the dots are positioned correctly, the numerical
> labels in the dotplot y axis are not correct.
That's comparing apples and oranges, sort of. You should use xyplot
instead of dotplot if you want the equivalent of plot (more precisely,
Although it's not obvious from your code, I'll bet your Y variable is
numeric with 9 unique values. dotplot treats one of its variables as a
factor. If neither variable are factors, it by default chooses the Y
variable is a factor. If it is numeric, as in your case, it converts it
into a 'shingle' (see ?shingle). This has almost the same effect as
coercion to a factor, except the Y values are labeled 1,2,... instead
of the levels.
> I put copies here:
> That is the "correct" one from plot, with the higest value on y
> showing at 18.
> That is the dotplot one. The picture is basically the same, except
> the numbers on the y axis only go up to 8. But the dots are in the
> correct spots and the x axis is labeled correctly.
They are not the same. The Y-spacing between the unique values are all
equal in dotplot, unlike in the plot output.
> On the screen, the plots have white backgrounds, but the picture from
> the dotplot turns out gray. Why is that? Sometimes, if I run another
> lattice plot in the same session, the colors change to the dark
> background, and I suppose the same trouble is happening. Isn't
> trellis.par.set() going to remain in place for all following trellis
Trellis settings are very much device-specific, and trellis.par.set only
affects the currently open device (much like par). You call it to
change the x11 settings, but you haven't changed the jpeg settings
anywhere, so the defaults are used.
What happens for new instances of the same device is a bit more subtle.
Once you change settings for a particular device type (say "x11"),
lattice remembers these settings. However, if you open a new instance
of this device with, say
the "x11" settings revert back to the x11 defaults (this behaviour can
be suppressed by an argument to trellis.device). Now, even if you don't
do this explicitly, any attempt to create a Trellis plot while there's
no currently active device results in a call to trellis.device, and
hence results in a new instance with the settings reset to defaults.
However, the settings are NOT reset if the device is already open.
An example to make things a bit less confusing (hopefully):
p <- xyplot(1~1)
p ## default (grey) background
p ## 'white' (actually transparent) background
p ## still white background, settings retained
p ## new instance of x11 started, settings reset,
## hence grey background
If you find this surprising, it's basically because lattice has no way
of knowing that a new device has been opened unless it's done through
trellis.device. Otherwise, the idea is to be similar to par and reset
the defaults everytime.
More information about the R-help