On Tue, 9 May 2000, Jim Lemon wrote:
> Denis White wrote:
>
> > How do I determine cex in
> >
> > points (x, y, pch=15, cex=?)
> >
> > to get a square whose side length is, say, 10 mm?
> >
> > thanks
>
> The easy way would be:
>
> points(6,3,pch=15,cex=10/(par("cin")[1]*25.4))
>
> That is, divide your desired width by the current width in inches
multiplied by
> 25.4,
>
> but this won''t _really_ give you a 10 mm square. The hardcopy
output you get
> depends upon the size of the image you generate (e.g. the "bounding
box" in
> Postscript). However, you could fudge it if you always use the same size
> output...
>
> Jim
>
Thanks for response from Jim Lemon. I tried 10/25.4/par("csi") and
several other ideas before submitting to r-help in frustration.
Below is a function that generates regular polygons, filled or
borders, of n sides (n>8 => circle), with "diameter" prescribed
in mm, for use alone or with apply.
############################################################
ngon <- function (xydc, n=4, type=1)
# draw or fill regular polygon
# xydc a four element vector with
# x and y of center, d diameter in mm, and c color
# n number of sides of polygon, n>8 => circle
# if n odd, vertex at (0,y), else midpoint of side
# type=1 => interior filled, type=2 => edge
# type=3 => both
{
u <- par("usr")
p <- par("pin")
d <- as.numeric(xydc[3])
inch <- d/25.4
rad <- inch*((u[2]-u[1])/p[1])/2
ys <- inch*((u[4]-u[3])/p[2])/2/rad
if (n > 8) n <- d*4 + 1
th <- pi*2/n
costh <- cos (th)
sinth <- sin (th)
x <- y <- rep (0,n+1)
if (n %% 2) {
x[1] <- 0
y[1] <- rad
}
else {
x[1] <- -rad*sin(th/2)
y[1] <- rad*cos(th/2)
}
for (i in 2:(n+1)) {
xl <- x[i-1]
yl <- y[i-1]
x[i] <- xl*costh - yl*sinth
y[i] <- xl*sinth + yl*costh
}
x <- x + as.numeric(xydc[1])
y <- y*ys + as.numeric(xydc[2])
if (type %% 2) polygon (x,y,col=xydc[4],border=0)
if (type %/% 2) lines (x,y,col=xydc[4])
invisible()
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._