Hello. I'm pretty much new to R and I'm trying to produce some figures. It seems to me, that R has some asynchronous way of plotting figures. When I run this code: #constructs the semivariogram of SC1929 vgm1 <- variogram(SC1929~1,~U+V,puerto.map$att.data) # trying to make new plot dev.set(which=dev.next()) plot(vgm1) title(main="Semivariogram",font.main=4) dev.copy2eps(file="fig2.eps",horizontal=T) dev.off() R complains that Error in title(main = "Semivariogram", font.main = 4) : plot.new has not been called yet So that plot(..) hasn't been executed before call of title. The most weird about that, if I add fix(vgm1) before dev.set(...), everything is just fine. Why R can't just perform commands one by one? P.S. I use Linux version of R. Thanks, Daniil.
On Sun, 20 Aug 2006, Daniil Ivanov wrote:> Hello. > > I'm pretty much new to R and I'm trying to produce some figures.What have you been reading to get the ideas below? People new to R do not tend to use dev.next ... indeed experienced users very rarely use it.> It seems to me, that R has some asynchronous way of plotting figures. > When I run this code:It will not run for us: please see the posting guide. You have forgotten to load some package here, and there are variogram() functions in at least packages gstat and spatial so we can't even tell what.> #constructs the semivariogram of SC1929 > vgm1 <- variogram(SC1929~1,~U+V,puerto.map$att.data) > > # trying to make new plot > dev.set(which=dev.next())What do think that does? It seems to say you want to plot on the null device, since no next device has been set.> plot(vgm1) > title(main="Semivariogram",font.main=4) > dev.copy2eps(file="fig2.eps",horizontal=T) > dev.off() > > R complains that > Error in title(main = "Semivariogram", font.main = 4) : > plot.new has not been called yet > > So that plot(..) hasn't been executed before call of title.That is _not_ what it says. A guess is that this is a lattice plot from package gstat, in which case plot.new has indeed not been called.> The most weird about that, if I add fix(vgm1) before > dev.set(...), everything is just fine. Why R can't just > perform commands one by one?It does. You cannot use title() to annotate a lattice plot, though.> P.S. I use Linux version of R. > > Thanks, Daniil. > > ______________________________________________ > R-help at stat.math.ethz.ch 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.PLEASE do as it asks. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Mon, 21 Aug 2006, Daniil Ivanov wrote:> Ok, what is wrong with a following code: > > # remove all the present objects > rm(list = ls()) > > # load the libraries we need > library(gstat) > > data(meuse) > vgm1 <- variogram(log(zinc)~1, ~x+y, meuse) > plot(vgm1) > dev.copy2eps(file="fig2.eps",horizontal=T) > dev.off() > > it plots nothing > but from the R consolegstat:::plot.gstatVariogram uses xyplot, a lattice graphics method, to make it easy to plot directional variograms. So please put print() round the plot(), see FAQ 7.22.> > plot(vgm1) > > gives me a plot. > > Thanks, Daniil. > > On 8/21/06, Daniil Ivanov <daniil.ivanov at gmail.com> wrote: > > Hi, > > > > Ok, thanks to all. > > Problem was with class of variogram > > > > > class(vgm1) > > [1] "gstatVariogram" "data.frame" > > > > If I fix it manually to > > > > class(vgm1) <- "gstatVariogram" > > > > everything runs as it should. > > > > Thanks, Daniil. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Hi, thank you very much for your help. In examples of gstat manual it was no print(). I thought it is like in Matlab, you take an example from the manual and it works. Silly me ;) Thanks, Daniil. On 8/21/06, Roger Bivand <Roger.Bivand at nhh.no> wrote:> On Mon, 21 Aug 2006, Daniil Ivanov wrote: > > > Ok, what is wrong with a following code: > > > > # remove all the present objects > > rm(list = ls()) > > > > # load the libraries we need > > library(gstat) > > > > data(meuse) > > vgm1 <- variogram(log(zinc)~1, ~x+y, meuse) > > plot(vgm1) > > dev.copy2eps(file="fig2.eps",horizontal=T) > > dev.off() > > > > it plots nothing > > but from the R console > > gstat:::plot.gstatVariogram uses xyplot, a lattice graphics method, to > make it easy to plot directional variograms. So please put print() round > the plot(), see FAQ 7.22. > > > > > plot(vgm1) > > > > gives me a plot. > > > > Thanks, Daniil. > > > > On 8/21/06, Daniil Ivanov <daniil.ivanov at gmail.com> wrote: > > > Hi, > > > > > > Ok, thanks to all. > > > Problem was with class of variogram > > > > > > > class(vgm1) > > > [1] "gstatVariogram" "data.frame" > > > > > > If I fix it manually to > > > > > > class(vgm1) <- "gstatVariogram" > > > > > > everything runs as it should. > > > > > > Thanks, Daniil. > > > > ______________________________________________ > > R-help at stat.math.ethz.ch 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. > > > > -- > Roger Bivand > Economic Geography Section, Department of Economics, Norwegian School of > Economics and Business Administration, Helleveien 30, N-5045 Bergen, > Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 > e-mail: Roger.Bivand at nhh.no > >