Re: [R] Graphics function question

From: Marc Schwartz <>
Date: Tue, 29 Jul 2008 13:45:12 -0500

Just a quick follow up to my own post here. In offline exchanges, Peter noted a typo in the call to plot(), where I was missing the final ")". Also, I had the order of the unnamed arguments to segments() off.

Here is the corrected code, with some additional teaks:

plotdiffs <- function(x, y, startage, endage, decline) {

   startvar <- x - y
   endvar <- x

   s1 <- seq(47, 89, length = 10)

   ymin <- min(startvar, endvar, na.rm = TRUE)    ymax <- max(startvar, endvar, na.rm = TRUE)

   s2 <- seq(ymin, ymax, length = 10)

   label <- gsub("^.+\\$", "", deparse(substitute(x)))

   plot(s1, s2, type = "n", xlab = "Age", ylab = label,

        main = paste("Age, decline and", label))

   segments(startage, startvar, endage, endvar, col = decline)

   legend("topleft", legend = c("Stable", "Decline"), lty = 1,

          col = c(1, 2))

Marc mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 29 Jul 2008 - 18:48:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jul 2008 - 19:32:53 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive