[R] split.screen problem and segments in figure margin
Marc Schwartz
MSchwartz at medanalytics.com
Sat Sep 6 18:35:16 CEST 2003
On Sat, 2003-09-06 at 10:01, Uwe Ligges wrote:
> Unternährer Thomas, uth wrote:
> > hi,
> >
> > two questions...
> >
> > 1. what happens with points()?
> > after the split.screen function points() start not at x = 1 (at x = - something)
> >
> > graphics.off()
> > x11()
> > split.screen(c(3, 1))
> > split.screen(c(2, 1), 1)
> >
> > screen(3)
> > plot(dat, type = "n")
> > screen(4)
> > plot(dat, type = "n")
> > screen(2)
> > plot(dat, type = "n")
> >
> > dat <- rnorm(1000)
> >
> > for (i in 1:length(dat)){
> > screen(3)
> > points(i, dat[i])
> > screen(4)
> > points(i, dat[i])
> > screen(2)
> > points(i, dat[i])
> > }
> >
> > close.screen(all = TRUE)
> >
> > I was searching the mail-archives and found the same question but no answers.
> > Can somebody help me?
>
> This is a bug, already submitted as bug report PR#2069.
> There are a couple of other unfixed bugs related to split.screen(), so
> I'd recommend to use layout() or par(mfrow = ..) in your case, or even
> better: consider to contribute a bugfix.
I may be missing something here, but in follow up to Uwe's reply, unless
you are specifically trying to demonstrate the bug, you are calling
plot(dat, ...) in each of the initial screens BEFORE 'dat' is defined in
your code.
At least the first time you run the code, you should get:
> screen(3)
> plot(dat, type = "n")
Error in plot(dat, type = "n") : Object "dat" not found
> screen(4)
> plot(dat, type = "n")
Error in plot(dat, type = "n") : Object "dat" not found
> screen(2)
> plot(dat, type = "n")
Error in plot(dat, type = "n") : Object "dat" not found
Of course, on each subsequent run of the code sequence, 'dat' is then
defined prior to the initial plot() calls if you don't rm(dat) each
time.
If you modify the code to:
graphics.off()
x11()
split.screen(c(3, 1))
split.screen(c(2, 1), 1)
# Define 'dat' here!
dat <- rnorm(1000)
x <- 1:1000
screen(3)
plot(dat, type = "n")
par("usr")
screen(4)
plot(dat, type = "n")
par("usr")
screen(2)
plot(dat, type = "n")
par("usr")
screen(3)
par("usr")
points(x, dat)
screen(4)
par("usr")
points(x, dat)
screen(2)
par("usr")
points(x, dat)
close.screen(all = TRUE)
It seems to run fine.
Note you do not require a for() loop for the calls to points() and that
for each of the par("usr") calls I get:
[1] -38.960000 1039.960000 -3.116957 3.958396
This is using R 1.7.1 under RH 9.
To lengthen the reply a bit, I also tried the following using different
vectors for 'dat' to be sure that there was not a residual problem with
par("usr"), given that all three original plots are using the same data:
graphics.off()
x11()
split.screen(c(3, 1))
split.screen(c(2, 1), 1)
dat4 <- rnorm(1000)
x <- 1:1000
dat2 <- dat4 * 2
dat3 <- dat4 * 3
screen(3)
plot(dat3, type = "n")
par("usr")
[1] -38.96000 1039.96000 -11.51162 10.63908
screen(4)
plot(dat4, type = "n")
par("usr")
[1] -38.960000 1039.960000 -3.837208 3.546360
screen(2)
plot(dat2, type = "n")
par("usr")
[1] -38.960000 1039.960000 -7.674416 7.092720
screen(3)
par("usr")
[1] -38.96000 1039.96000 -11.51162 10.63908
points(x, dat3)
screen(4)
par("usr")
[1] -38.960000 1039.960000 -3.837208 3.546360
points(x, dat4)
screen(2)
par("usr")
[1] -38.960000 1039.960000 -7.674416 7.092720
points(x, dat2)
close.screen(all = TRUE)
HTH,
Marc Schwartz
More information about the R-help
mailing list