# [S] trellis graphics problem

Matthew Wiener (mcw@ln.nimh.nih.gov)
Thu, 15 Oct 1998 10:20:02 -0400 (EDT)

I have written a small program to do polar plots.
Should be straightforward: convert to Cartesian and plot.
The problem is, what I've done doesn't actually plot anything to the
screen, and I can't figure out why. It's probably something trivial, but
it's driving me crazy. Any assistance would be greatly appreciated.
The function is below.

I'm using Splus 3.4 on an SGI, and I have checked that my graphics are
working and that xyplot works from the command line.

Thanks, Matt

-------------------------------------------------------------

The function:

function(r, theta, groups = NULL, degrees = T) { # r and theta are
vectors containing the radii and angles # (in degrees, by default; can
specify radians) of the # points to be plotted #
if(degrees) { # convert to radians if needed Sample output:
theta <- ((theta * pi)/180)
}
if(sum(r < 0) > 0) { # check for negative radii; reject
stop(message = paste("Error: ", sum(r < 0),
" radius values < 0", sep = ""))
}
oldpar <- par()
par(pty = "s")
x <- r * cos(theta) # convert to Cartesian
y <- r * sin(theta)
extreme.r <- max(r)
lim.vec <- c( - extreme.r, extreme.r) #
# if no groups given, construct single group
if(is.null(groups)) {
groups <- rep("1", length(r))
} #
write(t(cbind(r, (theta * 180)/pi, x, y, groups)), ncol = 5, file
= "")
my.panel <- function(x, y, ...)
{
panel.superpose(x, y, ...)
panel.abline(h = 0)
panel.abline(v = 0)
}
xyplot(y ~ x, xlab = "", ylab = "", xlim = lim.vec, ylim =
lim.vec, panel = my.panel, groups = groups) #
# xyplot(y ~ x, xlab = "",ylab = "", xlim = lim.vec, ylim = lim.vec)
par(pty = "")
NULL
}

Sample output:

> polarplot(c(5,10,15),c(45,45,45),c("1","1","1"))
5 45 3.53553390593274 3.53553390593274 1
10 45 7.07106781186547 7.07106781186547 1
15 45 10.6066017177982 10.6066017177982 1

NULL

but no graph!

Leaving the groups as NULL, or using the commented out xyplot without my
panel function, also fails to print anything.

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news