[R] malformed plot symbols in lattice pdf

Mark Wilkinson wilkinsonmr at gmail.com
Fri Mar 13 20:13:17 CET 2009


Hi,

I'm using panel.polygon inside a custom panel function to generate
filled polygons for an xyplot.  Everything is as expected until I
specify a value < 1 for alpha to fill with a semi-transparent color
and output to pdf.  The plot symbols appear malformed.  Am I doing
something wrong here?

Thanks,
Mark

Here is an example (pdfs are attached):

library(lattice)

## example data
set.seed(101)
ex.data <- data.frame(x = sort(runif(10)),
                      y = rnorm(10))

## plot an opaque polygon
ex.panel1 <- function(x, y) {
    yy.up <- y + 0.25
    yy.lo <- y - 0.25
    panel.polygon(c(x, rev(x)), c(yy.up, rev(yy.lo)),
                  border = NA, col = "lightblue", alpha = 1)
    panel.xyplot(x, y, type = "p")
}

## output to pdf (this one is OK)
trellis.device(device = pdf, color = TRUE, file = "plt1.pdf")
xyplot(y ~ x, data = ex.data, panel = ex.panel1)
dev.off()

## plot a semi-transparent polygon
ex.panel2 <- function(x, y, alpha) {
    yy.up <- y + 0.25
    yy.lo <- y - 0.25
    panel.polygon(c(x, rev(x)), c(yy.up, rev(yy.lo)),
                  border = NA, col = "lightblue", alpha = 0.5) # note change
    panel.xyplot(x, y, type = "p")
}

## output to pdf (symbols are now malformed)
trellis.device(device = pdf, color = TRUE, file = "plt2.pdf")
xyplot(y ~ x, data = ex.data, panel = ex.panel2)
dev.off()

> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lattice_0.17-17

loaded via a namespace (and not attached):
[1] grid_2.8.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plt1.pdf
Type: application/pdf
Size: 4000 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090313/68365322/attachment-0006.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plt2.pdf
Type: application/pdf
Size: 4190 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090313/68365322/attachment-0007.pdf>


More information about the R-help mailing list