[R] Transparent Pie Charts
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sun Feb 13 14:54:20 CET 2005
Werner Wernersen wrote:
> Hi again!
>
> I put this question in another topics post before but
> I fear it might drown there.
>
> Is it possible to have transparent / alpha blended
> colors for pie charts?
> I am using the pies in a map of pies and those pies
> are sometimes overlapping so
> it would be great to see if another pie lies beneath.
>
> Thanks,
> Werner
>
> ______________________________________________
> 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
You have already found Paul Murrell's R News 3(2) article. You might
also want to take a look at the page of his forthcoming book:
http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html
For transparency/alpha blending see the article "Fonts, Lines and
Transparency in R Graphics" in the latest R News 4(2). Transparency
works on many devices, alpha blending only on a few (pdf, for example).
Let's change Paul's code from R News 3(2) to allow transparency:
x <- c(0.88, 1, 0.67, 0.34)
y <- c(0.5, 0.4, 0.6, 0.55)
set.seed(1234)
z <- matrix(runif(4 * 2), ncol = 2)
oldpar <- par(no.readonly = TRUE)
plot(x, y, xlim = c(-0.2, 1.2), ylim = c(-0.2, 1.2), type = "n")
vps <- baseViewports()
par(new = TRUE)
pushViewport(vps$inner, vps$figure, vps$plot)
grid.segments(x0 = unit(c(rep(0, 4), x), rep(c("npc", "native"),
each = 4)),
x1 = unit(c(x, x), rep("native", 8)),
y0 = unit(c(y, rep(0, 4)), rep(c("native", "npc"),
each = 4)),
y1 = unit(c(y, y), rep("native", 8)),
gp = gpar(lty = "dashed", col = "grey"))
maxpiesize <- unit(1, "inches")
totals <- rowSums(z)
sizemult <- totals/max(totals)
for (i in 1:4) {
pushViewport(viewport(x = unit(x[i], "native"),
y = unit(y[i], "native"),
width = sizemult[i] * maxpiesize,
height = sizemult[i] * maxpiesize))
grid.rect(gp = gpar(col = "grey", lty = "dashed"))
par(plt = gridPLT(), new = TRUE)
pie(z[i, ], radius = 1, labels = rep("", 2),
col = c("transparent", "lightblue"))
popViewport()
}
popViewport(3)
par(oldpar)
Uwe Ligges
More information about the R-help
mailing list