Several gstat variograms on a single page
Thank you Edzer, you're right, the layout I wanted to get can be produced just using simple 'graphics' functions. I've already 'discovered' how to do it. At this stage, I find Lattice and Grid graphics too complex. The biggest problem is to understand how particular features of a lattice/grid plot are controlled. However, step by step, I am getting there. Best wishes, Michal
On May 3 2007, Edzer J. Pebesma wrote:
Michal, I think (and hope for you) it is not necessary to search the solution at the level of grid. The plot function for variograms in package gstat is a rather (?) thin wrapper around xyplot, so if you carefully read how to control the main and sub arguments of ?xyplot, then you're done: library(gstat) data(meuse) coordinates(meuse)=~x+y v = variogram(log(zinc)~1,meuse) v.pl = plot(v, main="log-zinc",sub=list(label = "xx", cex=.5)) Next you can print the v.pl etc. objects side by side using print(v.pl, more = TRUE) etc. -- Edzer Michal Gallay wrote:
Dear R Users,
I'd like to ask you for help. I am R beginner, tackling R for about
three months. I'd like to produce variograms with 0, 1st, 2nd order
detrending for 30 ascii grid files containing elevation data.
I've got problem with a simple thing but as it seems to me not as easy
one as I thought. I hope I just can't see because of my eyes.
I'd like to plot three gstat variograms in one row on one page, to give
them a main title (just single one for all three of the plots), and for
each of the plots a subtitle, controlling the fontsize.
At first I used following approach:
#Calculation of the variogram and store it in a variable var...
g <- gstat(id = "xyz.values",
formula=z~1,
locations = ~x+y,
data = xyz.values,
set = list(fraction = 0.33, width = 2))
var.0ot <- variogram(g)
g <- gstat(id = "xyz.values",
formula=z~x+y,
locations = ~x+y,
data = xyz.values,
set = list(fraction = 0.33, width = 2))
var.1ot <- variogram(g)
g <- gstat(id = "xyz.values",
formula= z~x + y + I(x*y) + I(x^2) + I(y^2),
locations = ~x+y,
data = xyz.values,
set = list(fraction = 0.33, width = 2))
var.2ot <- variogram(g)
#Store the plot it in a variable plot.var...
plot.var.0ot <- plot(var.0ot, pch=3, cex=0.5, col="red",
main="No trend removed")
plot.var.1ot <- plot(var.1ot, pch=3, cex=0.5, col="red",
main="1st order trend removed")
plot.var.2ot <- plot(var.2ot, pch=3, cex=0.5, col="red",
main="2st order trend removed")
#Print the variograms into regions as specified
print(plot.var.0ot, split=c(1,1,3,1), more=T)
print(plot.var.1ot, split=c(2,1,3,1), more=T)
print(plot.var.2ot, split=c(3,1,3,1), more=F)
The variograms were plotted OK, however, via that approach I couldn't
figure out how to change the font size of the subtitles of each graph
(specified by main="No trend" etc.)'par'or 'title' didn't work or I
didn't use them right way. Further, I wasn't able to plot the main
title positioned above the three subtitles and graphs.
So I thought the problem will be sorted if I use 'grid' package as
plot.gstat Variogram function obeys 'lattice'.
I've created a viewport of 3 by 3 grid layout (after Paul Murrell
http://www.stat.auckland.ac.nz/~paul/grid/grid.html#docs) and viewport
tree. First row accommodates main title. This works fine. The second
row and first column includes just the subtitle 1, second column
subtitle 2, third column subtitle 3.
Third row is dedicated to the variogram plots. However, they are not
plotted into the viewports plot1, plot2, plot3, but on the whole page.
The approach was as follows:
top.vp <- viewport(layout = grid.layout(3,3,widths=unit(c(1,1,1),
c("null", "null", "null")), heights=unit(c(1,1,1), c("lines", "lines",
"null"))))
vp.main.title <- viewport(layout.pos.col=c(1:3),layout.pos.row=1,
name="vp.main.title") vp.subtitle1 <-
viewport(layout.pos.col=1,layout.pos.row=2, name="vp.subtitle1")
vp.subtitle2 <- viewport(layout.pos.col=2,layout.pos.row=2,
name="vp.subtitle2") vp.subtitle3 <-
viewport(layout.pos.col=3,layout.pos.row=2, name="vp.subtitle3")
vp.plot1 <- viewport(layout.pos.col=1,layout.pos.row=3,
name="vp.plot1") vp.plot2 <-
viewport(layout.pos.col=2,layout.pos.row=3, name="vp.plot2") vp.plot3
<- viewport(layout.pos.col=3,layout.pos.row=3, name="vp.plot3")
splot <- vpTree(top.vp, vpList(vp.main.title, vp.subtitle1,
vp.subtitle2, vp.subtitle3,vp.plot1, vp.plot2, vp.plot3))
pushViewport(splot)
seekViewport("vp.main.title")
grid.text("main title", gp=gpar(cex=1.2))
seekViewport("vp.subtitle1")
grid.text("subtitle 1", gp=gpar(cex=0.8))
seekViewport("vp.plot1")
plot(var.0ot, pch=3, cex=0.5, col="red")
I much appreciate any suggestions and criticism.
Thank you very much in advance.
Michal
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Michal Gallay Postgraduate Research Student School of Geography, Archaeology and Palaeoecology Queen's University Belfast BT7 1NN Northern Ireland Tel: +44(0)2890 273929 Fax: +44(0)2890 973212 email: mgallay01 at qub.ac.uk www: www.qub.ac.uk/geog