[R] pie graphs in log scale axis

David Winsemius dwinsemius at comcast.net
Mon Oct 28 17:42:26 CET 2013


On Oct 28, 2013, at 6:40 AM, Ortiz, John wrote:

>
> Dear list users,
>
>
> I'm doing a plot integrating Grid output with Base Graphics output   
> (gridBase, Murrell 2012).
>
> My goal is to produce a xy plot where each point is represented by a  
> pie.  I could get it using the attach code,
> but now I want to change the X axis to log scale.
>
> when I introduce the log="x" parameter in the line:
>
> plot(x, y, xlim=c(0.1, 1.2), log="x", ylim=c(0.1, 1.2), type="n")
>
> I get this warning!
>
> vps <- baseViewports()
> Warning message:
> In baseViewports() : viewport scales NOT set to user coordinates
>
>
> This is the code to produce it without introduce log scale yet:
>
> library(grid)
> library(gridBase)
> x <- c(0.88, 1.00, 0.67, 0.34)
> y <- c(0.87, 0.43, 0.24, 0.94)
> z <- matrix(runif(4*2), ncol=2)
>
> oldpar <- par(no.readonly=TRUE)
>
> plot(x, y, xlim=c(0.1, 1.2), ylim=c(0.1, 1.2), type="n")
>
> vps <- baseViewports()
> pushViewport(vps$inner, vps$figure, vps$plot)
>
> for (i in 1:4) {
> pushViewport(viewport(x=unit(x[i], "native"),
> y=unit(y[i], "native"),
> width=0.1,
> height=0.1))
> par(plt=gridPLT(), new=TRUE)
> pie(z[i,], radius=1, labels=rep("", 2))
> popViewport()
> }
>
> popViewport(2)
> par(oldpar)
>
> Thanks by some advice!!

I haven't figured out the ratinale for this effort but this does  
result in a base log="xy" plot with pies

  library(grid)
library(gridBase)
x <- c(0.88, 1.00, 0.67, 0.34)
y <- c(0.87, 0.43, 0.24, 0.94)
z <- matrix(runif(4*2), ncol=2)

oldpar <- par(no.readonly=TRUE)

plot(x, y, xlim=c(0.01, 1.2), ylim=c(0.01, 1.2), type="n", log="xy")

# Note need to modify limits

vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)

for (i in 1:4) {
pushViewport(viewport(x=unit(log(x[i]), "native"),
# this seemed the sensible strategy
y=unit(log(y[i]), "native"),
# Didn't think log(units(...)) would be as successful
width=0.1,
height=0.1))
par(plt=gridPLT(), new=TRUE)
pie(z[i,], radius=1, labels=rep("", 2))
popViewport()
}

popViewport(2)
par(oldpar)

>
> Regards,
>
>
> John Ortiz
>
> Geologist
> Smithsonian Tropical Research Institute Panama
>
> ______________________________________________
> 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.

David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list