Skip to content
Prev 178546 / 398506 Next

problem with symbol function

On 27/04/2009 5:23 PM, Christophe Dutang wrote:
It's not graphics on Windows, but it appears to be a limitation of the 
windows() graphics device in R.  It is used for bitmap plots as well as 
on-screen plots, which is why you saw the same effect in jpeg, but 
different devices are used for Postscript and PDF.

When drawing lines, R handles the dash style itself, rather than using 
the built-in dashes.  But it doesn't do so for circles, and doesn't make 
use of the Windows line styles.

If you really need the dashes onscreen, you can draw the circle 
yourself.  Assuming the scales are equal on both axes that's easy, just use

 > theta <- seq(0,2*pi, len=256)
 > lines(x+r*cos(theta), y+r*sin(theta), lty="dashed")

(where (x,y) is the center and r is the radius).  It's more work if you 
want things to appear as circles when the scales are unequal, but I 
think this works:

circle <- function(x, y, inches=1, ...) {
   theta <- seq(0, 2*pi, len=256)
   lines(x + grconvertX(inches*cos(theta), "inches", "user") - 
grconvertX(0, "inches", "user"),
         y + grconvertY(inches*sin(theta), "inches", "user") -
grconvertY(0, "inches", "user"),
         ...)
}

so you'd get the plot you wanted using

circle(0, 0, inches = 1.5, fg="black",lty="dashed")

The circle function is not vectorized, so it's not as useful as symbols, 
but it could be improved.

Duncan Murdoch