File: gridBase.R

package info (click to toggle)
r-cran-gridbase 0.4-7-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 340 kB
  • sloc: sh: 16; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# A base plot with grid viewports synchronised then
# further grid viewports pushed to contain pie charts

x <- runif(4)
y <- runif(4)
z <- matrix(runif(4*2), ncol=2)

maxpiesize <- unit(1, "inches")
totals <- apply(z, 1, sum)
sizemult <- totals/max(totals)

oldomi <- par("omi")
plot(x, y, xlim=c(-0.2, 1.2), ylim=c(-0.2, 1.2), type="n")
vps <- baseViewports()
# First grid action will trigger a new page unless we do this
# Should be able to avoid this yuckiness in the future
par(new=TRUE)
pushViewport(vps$inner, vps$figure, vps$plot)
grid.grill(h=y, v=x, default.units="native")
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", fill="white", lty="dashed"))
  par(mar=rep(0, 4), omi=gridOMI(), new=TRUE)
  pie(z[i,], radius=1, labels=rep("", 2))
  popViewport()
}
popViewport(3)
par(omi=rep(0, 4), mar=c(5.1, 5.1, 4.1, 2.1))