Discussion:
[R] Ternary Plots Do Not Display Ellipses in PDF
Rich Shepard
2014-10-14 22:00:59 UTC
Permalink
A rather strange situation here and I've not found the source of the
problem.

The point is to print a ternary plot matrix of compositional data with
ellipses enclosing 95% of the variance in each plot. The ellipses display on
the monitor, dev = x11cairo, but not when sent directly to a file, dev =
pdf.

Here's winters.acomp:

structure(c(0.0666666666666667, 0.0612244897959184, 0.0434782608695652,
0.043956043956044, 0.05, 0.0161290322580645, 0.6, 0.571428571428571,
0.623188405797101, 0.593406593406593, 0.433333333333333, 0.629032258064516,
0.0666666666666667, 0.0612244897959184, 0.101449275362319, 0.0659340659340659,
0.0666666666666667, 0.032258064516129, 0.244444444444444, 0.26530612244898,
0.217391304347826, 0.263736263736264, 0.366666666666667, 0.290322580645161,
0.0222222222222222, 0.0408163265306122, 0.0144927536231884, 0.032967032967033,
0.0833333333333333, 0.032258064516129), .Dim = c(6L, 5L), .Dimnames = list(
NULL, c("filter", "gather", "graze", "predate", "shred")), class = "acomp")
library(compositions)
plot(winters.acomp, main="Winters Creek", cex=0.5)
r <- sqrt(qchisq(p=0.95, df=4))
mn <- mean(winters.acomp)
vr <- var(winters.acomp)
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
# monitor plot window is manually closed.
pdf("winters-pdf.pdf")
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
dev.off()
What am I not seeing here that causes the different outputs?

Rich
Rolf Turner
2014-10-14 23:25:03 UTC
Permalink
print(ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL,
aspanel=FALSE,col='red', lwd=2))
cheers,

Rolf Turner

P. S. See also fortune(123).

R. T.
A rather strange situation here and I've not found the source of the
problem.
The point is to print a ternary plot matrix of compositional data with
ellipses enclosing 95% of the variance in each plot. The ellipses display on
the monitor, dev = x11cairo, but not when sent directly to a file, dev =
pdf.
structure(c(0.0666666666666667, 0.0612244897959184, 0.0434782608695652,
0.043956043956044, 0.05, 0.0161290322580645, 0.6, 0.571428571428571,
0.623188405797101, 0.593406593406593, 0.433333333333333,
0.629032258064516, 0.0666666666666667, 0.0612244897959184,
0.101449275362319, 0.0659340659340659, 0.0666666666666667,
0.032258064516129, 0.244444444444444, 0.26530612244898,
0.217391304347826, 0.263736263736264, 0.366666666666667,
0.290322580645161, 0.0222222222222222, 0.0408163265306122,
0.0144927536231884, 0.032967032967033, 0.0833333333333333,
0.032258064516129), .Dim = c(6L, 5L), .Dimnames = list(
NULL, c("filter", "gather", "graze", "predate", "shred")), class = "acomp")
library(compositions)
plot(winters.acomp, main="Winters Creek", cex=0.5)
r <- sqrt(qchisq(p=0.95, df=4))
mn <- mean(winters.acomp)
vr <- var(winters.acomp)
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
# monitor plot window is manually closed.
pdf("winters-pdf.pdf")
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
dev.off()
What am I not seeing here that causes the different outputs?
--
Rolf Turner
Technical Editor ANZJS
Rich Shepard
2014-10-14 23:40:07 UTC
Permalink
Post by Rolf Turner
print(ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL,
aspanel=FALSE,col='red', lwd=2))
Rolf,

Thank you. Didn't occur to me to look in the FAQ for this issue.
Post by Rolf Turner
P. S. See also fortune(123).
OK.

Regards,

Rich
Rich Shepard
2014-10-14 21:20:40 UTC
Permalink
A rather strange situation here and I've not found the source of the
problem.

The point is to print a ternary plot matrix of compositional data with
ellipses enclosing 95% of the variance in each plot. The ellipses display on
the monitor, dev = x11cairo (see attached winters-x11cairo.pdf), but not when
sent directly to a file, dev = pdf (see attached winters-pdf.pdf).

Here's winters.acomp:

structure(c(0.0666666666666667, 0.0612244897959184, 0.0434782608695652,
0.043956043956044, 0.05, 0.0161290322580645, 0.6, 0.571428571428571,
0.623188405797101, 0.593406593406593, 0.433333333333333, 0.629032258064516,
0.0666666666666667, 0.0612244897959184, 0.101449275362319, 0.0659340659340659,
0.0666666666666667, 0.032258064516129, 0.244444444444444, 0.26530612244898,
0.217391304347826, 0.263736263736264, 0.366666666666667, 0.290322580645161,
0.0222222222222222, 0.0408163265306122, 0.0144927536231884, 0.032967032967033,
0.0833333333333333, 0.032258064516129), .Dim = c(6L, 5L), .Dimnames = list(
NULL, c("filter", "gather", "graze", "predate", "shred")), class = "acomp")
library(compositions)
plot(winters.acomp, main="Winters Creek", cex=0.5)
r <- sqrt(qchisq(p=0.95, df=4))
mn <- mean(winters.acomp)
vr <- var(winters.acomp)
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
# monitor plot window is manually closed.
pdf("winters-pdf.pdf")
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
dev.off()
What am I not seeing here that causes the different outputs?

Rich
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winters-x11cairo.pdf
Type: application/pdf
Size: 178553 bytes
Desc:
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20141014/f12157aa/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winters-pdf.pdf
Type: application/pdf
Size: 181383 bytes
Desc:
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20141014/f12157aa/attachment-0001.pdf>
David L Carlson
2014-10-15 14:09:54 UTC
Permalink
plot(winters.acomp, main="Winters Creek", cex=0.5)
pdf("winters-pdf.pdf")
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
+ col='red', lwd=2)
dev.off()
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rich Shepard
Sent: Tuesday, October 14, 2014 4:21 PM
To: r-help at r-project.org
Subject: [R] Ternary Plots Do Not Display Ellipses in PDF

A rather strange situation here and I've not found the source of the
problem.

The point is to print a ternary plot matrix of compositional data with
ellipses enclosing 95% of the variance in each plot. The ellipses display on
the monitor, dev = x11cairo (see attached winters-x11cairo.pdf), but not when
sent directly to a file, dev = pdf (see attached winters-pdf.pdf).

Here's winters.acomp:

structure(c(0.0666666666666667, 0.0612244897959184, 0.0434782608695652,
0.043956043956044, 0.05, 0.0161290322580645, 0.6, 0.571428571428571,
0.623188405797101, 0.593406593406593, 0.433333333333333, 0.629032258064516,
0.0666666666666667, 0.0612244897959184, 0.101449275362319, 0.0659340659340659,
0.0666666666666667, 0.032258064516129, 0.244444444444444, 0.26530612244898,
0.217391304347826, 0.263736263736264, 0.366666666666667, 0.290322580645161,
0.0222222222222222, 0.0408163265306122, 0.0144927536231884, 0.032967032967033,
0.0833333333333333, 0.032258064516129), .Dim = c(6L, 5L), .Dimnames = list(
NULL, c("filter", "gather", "graze", "predate", "shred")), class = "acomp")
library(compositions)
plot(winters.acomp, main="Winters Creek", cex=0.5)
r <- sqrt(qchisq(p=0.95, df=4))
mn <- mean(winters.acomp)
vr <- var(winters.acomp)
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
# monitor plot window is manually closed.
pdf("winters-pdf.pdf")
plot(winters.acomp, main="Winters Creek", cex=0.5)
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
dev.off()
What am I not seeing here that causes the different outputs?

Rich
Rich Shepard
2014-10-15 14:20:25 UTC
Permalink
I haven't looked at the source so I don't know exactly what is going on,
but I think I have a work around. While running your example I noticed
that ellipse() does not just add the ellipse to the plot produced by
plot(), it replots the figure. However, just running ellipse() without
plot() generates an error "Error in if (coorgeo == "acomp") { : argument
is of length zero" so ellipse needs the plot environment produced by
plot(winters.acomp, main="Winters Creek", cex=0.5)
pdf("winters-pdf.pdf")
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
+ col='red', lwd=2)
dev.off()
David,

How interesting! I saw what I now know as the plot being redrawn when the
ellipses were added but did not recognize the significance. I'll try this
in a while but it should work here, too.

Much appreciated,

Rich
Rich Shepard
2014-10-15 16:00:48 UTC
Permalink
I haven't looked at the source so I don't know exactly what is going on,
plot(winters.acomp, main="Winters Creek", cex=0.5)
pdf("winters-pdf.pdf")
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
+ col='red', lwd=2)
dev.off()
library(compositions)
plot(winters.acomp, main="Winters Creek", cex=0.5)
r <- sqrt(qchisq(p=0.95, df=4))
mn <- mean(winters.acomp)
vr <- var(winters.acomp)
pdf("winters-ffg-prop.pdf")
ellipses(mean=mn, var=vr, r=r, steps=72, thinRatio=NULL, aspanel=FALSE,
col='red', lwd=2)
Error in if (coorgeo == "acomp") { : argument is of length zero
dev.off()
So it works for David and Rolf, but not for me. Environment: R-3.1.1 on
Slackware-14.1 in Emacs-24.3 with ESS-13.09-1 and compositions-1.40-1.

I would appreciate assistance from one of you R gurus in finding the
source of this problem and fixing it. Communicating off the mail list (until
the solution is reached) might be a good idea to avoid clutter.

TIA,

Rich

Loading...