[R] How to correct this

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Mon Nov 22 05:40:20 CET 2004



Jin.Li at csiro.au wrote:

> Hi there,
> 
>  
> 
> I tried to add a few circles on an existing figure using the following
> codes
> 
>  
> 
> grid.circle(x=0.5, y=0.5, r=0.1, draw=TRUE,  gp=gpar(col=5))
> 
> grid.circle(x=0.5, y=0.5, r=0.3, draw=TRUE, gp=gpar(col=5))
> 
> grid.circle(x=0.5, y=0.5, r=0.5, draw=TRUE, gp=gpar(col=5))
> 
> points(0.5, 0.5, col = 5) # centre of the circle
> 
>  
> 
> , but all circles moved away from the centre.  Could we do any
> corrections to this? Thanks.
> 
>  
> 
> Regards,
> 
>  
> 
> Jin
> 

If you are using Lattice (where grid is a more natural fit) then you can 
do the following:

library(lattice)
library(grid)
xyplot(0.5 ~ 0.5,
        panel = function(x, y, ...) {
          grid.circle(x, y, 0.5, default.units = "native")
          panel.xyplot(x, y, ...)
        },
        xlim = c(0, 1),
        ylim = c(0, 1))

I'm not sure how grid is supposed to behave in a non-trellis.device.

--sundar




More information about the R-help mailing list