[R] Defining a viewport scale in {Grid}
baptiste auguie
baptiste.auguie at googlemail.com
Thu Feb 16 20:39:54 CET 2012
The default units of polygonGrob are "npc", I think you want "native" instead.
Try the following,
library(grid)
d = data.frame(x=rnorm(100, 10), y=rnorm(100, -100))
v = dataViewport(xData=d$x, yData=d$y)
grid.points(d$x,d$y, default.units="native", vp=v)
HTH,
b.
On 17 February 2012 02:47, geotheory <geotheory1 at gmail.com> wrote:
> Am just feeling my way into the grid library, and cannot figure out how to
> define the plot limits. 3/5 of the example polygons below plot in the
> default 0-1 range viewport. But when I try to redefine the viewport the
> polygons plot in the same places. I also get the same result without
> employing push/pop. (As you can see from the scale I'm trying to introduce,
> I want to plot map polygons.) Grateful for an idea where I'm going wrong.
>
> pushViewport(viewport(xscale=c(-180,180),yscale=c(-90,90)))
>
> grid.polygon(x=c(0,5,5,0)/100, y=c(0,0,5,5)/100, draw = T)
> grid.polygon(x=c(100,95,95,100)/100, y=c(100,100,95,95)/100, draw = T)
> grid.polygon(x=c(50,70,70,50)/100, y=c(50,50,70,70)/100, draw = T)
> grid.polygon(x=-c(10,10,40,40)/100, y=c(10,40,40,10)/100, draw = T)
> #NEGATIVE X
> grid.polygon(x=c(50,52,52,50)/100, y=-c(50,50,52,52)/100, draw = T)
> #NEGATIVE Y
>
> popViewport()
>
> Thanks in advance.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Defining-a-viewport-scale-in-Grid-tp4393974p4393974.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list