[R] Cropped graph using lattice

Susan Durham Susan.Durham at usu.edu
Thu Mar 18 00:24:19 CET 2010


Paul,

Yes, perfect!  Thank you!

Susan

~~~
Susan Durham
Utah State University
Ecology Center
5205 Old Main Hill
Logan, UT 84322-5205
(435)797-1337
 

> -----Original Message-----
> From: Paul Murrell [mailto:p.murrell at auckland.ac.nz]
> Sent: Wednesday, March 17, 2010 5:13 PM
> To: Susan Durham
> Cc: r-help at r-project.org
> Subject: Re: [R] Cropped graph using lattice
> 
> Hi
> 
> Susan Durham wrote:
> > I'm fitting data from a mixture experiment, and I'd like to present
> > the results in a ternary graph with contours.  I found this code by
> > Walmes Zeviani
> >
> > http://n4.nabble.com/Triangular-filled-contour-plot-td1557386.html
> >
> > which is just what I want--except I would like the axis titles and
> > labels to be proportionately larger than the ternary graph itself,
> > for legibility in publication.  When I increase the cex, the figure
> > is cropped.  I've spent a lot of time in the help files and Murrell's
> > book, and searched archives trying to sort this out, with no success.
> >
> >
> > I am running the code included below with R 2.10.1 on Windows XP
> > Professional.
> 
> This may just be a matter of expanding the axis limits, e.g., ... ?
> 
> levelplot(yhat~base*high, trian, aspect="iso",
>            ## HERE
>            xlim=c(-0.5,1.5), ylim=c(-0.5,1.5),
> 	  ## HERE
>            xlab=NULL, ylab=NULL, contour=TRUE,
>            colorkey=list(space="bottom", labels=list(col=1, cex=1.3)),
>            par.settings=list(axis.line=list(col=NA),
>                              axis.text=list(col=NA)),
>            panel=function(..., at, contour=TRUE, labels=NULL){
>              panel.levelplot(..., at=at, contour=contour,
> #labels=labels,
>                              lty=3, lwd=0.5, col=1)
>            })
> 
> Paul
> 
> > Thank you, in advance, for your help.
> >
> > Susan ~~~ Susan Durham Ecology Center Utah State University
> >
> >
> > library(grid) library(lattice)
> >
> > paint <- data.frame(mono=c(17.5, 10, 15, 25, 5, 5, 11.25, 5, 18.13,
> > 8.13, 25, 15, 10, 5), cross=c(32.5, 40, 25, 25, 25, 32.5, 32.5, 40,
> > 28.75, 28.75, 25, 25, 40, 25), resin=c(50, 50, 60, 50, 70, 62.5,
> > 56.25, 55, 53.13, 63.13, 50, 60, 50, 70), hardness=c(29, 26, 17, 28,
> > 35, 31, 21, 20, 29, 25, 19, 14, 30, 23))
> >
> > pseudo <- with(paint, data.frame(mono=(mono-5)/(25-5),
> > resin=(resin-50)/(70-50))) pseudo$cross <- with(pseudo, 1-mono-resin)
> >  pseudo$hardness <- paint$hardness
> >
> > m1 <- lm(hardness~(mono+cross+resin)^2-mono, data=pseudo)
> >
> > trian <- expand.grid(base=seq(0,1,l=100*2),
> > high=seq(0,sin(pi/3),l=87*2)) trian <- subset(trian,
> > (base*sin(pi/3)*2)>high) trian <- subset(trian,
> > ((1-base)*sin(pi/3)*2)>high)
> >
> > new2 <- data.frame(cross=trian$high*2/sqrt(3)) new2$resin <-
> > trian$base-trian$high/sqrt(3) new2$mono <- 1-new2$resin-new2$cross
> >
> > trian$yhat <- predict(m1, newdata=new2)
> >
> > grade.trellis <- function(from=0.2, to=0.8, step=0.2, col=1, lty=2,
> > lwd=0.5){ x1 <- seq(from, to, step) x2 <- x1/2 y2 <- x1*sqrt(3)/2 x3
> > <- (1-x1)*0.5+x1 y3 <- sqrt(3)/2-x1*sqrt(3)/2 panel.segments(x1, 0,
> > x2, y2, col=col, lty=lty, lwd=lwd) panel.text(x1, 0, label=x1, pos=1,
> > cex=1.3) panel.segments(x1, 0, x3, y3, col=col, lty=lty, lwd=lwd)
> > panel.text(x2, y2, label=rev(x1), pos=2, cex=1.3) panel.segments(x2,
> > y2, 1-x2, y2, col=col, lty=lty, lwd=lwd) panel.text(x3, y3,
> > label=rev(x1), pos=4, cex=1.3) }
> >
> > levelplot(yhat~base*high, trian, aspect="iso", xlim=c(-0.1,1.1),
> > ylim=c(-0.1,0.96), xlab=NULL, ylab=NULL, contour=TRUE,
> > colorkey=list(space="bottom", labels=list(col=1, cex=1.3)),
> > par.settings=list(axis.line=list(col=NA), axis.text=list(col=NA)),
> > panel=function(..., at, contour=TRUE, labels=NULL){
> > panel.levelplot(..., at=at, contour=contour, #labels=labels, lty=3,
> > lwd=0.5, col=1) }) trellis.focus("panel", 1, 1, highlight=FALSE)
> > panel.segments(c(0,0,0.5), c(0,0,sqrt(3)/2), c(1,1/2,1),
> > c(0,sqrt(3)/2,0)) grade.trellis() panel.text(0, 0, label="mono",
> > pos=2, cex=1.3) panel.text(1/2, sqrt(3)/2, label="cross", pos=3,
> > cex=1.3) panel.text(1, 0, label="resin", pos=4, cex=1.3)
> > trellis.unfocus()
> >
> > ______________________________________________ R-help at r-project.org
> > 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.
> 
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list