[Rd] I wish xlim=c(0, NA) would work. How about I send you a patch?

From: Paul Johnson <pauljohn32_at_gmail.com>
Date: Mon, 16 Apr 2012 12:52:30 -0500


I'm looking for an R mentor. I want to propose a change in management of plot options xlim and ylim.

Did you ever want to change one coordinate in xlim or ylim? It happens to me all the time.

x <- rnorm(100, m=5, s=1)
y <- rnorm(100, m=6, s=1)
plot(x,y)

## Oh, I want the "y axis" to show above x=0.

plot(x,y, xlim=c(0, ))

##Output: Error in c(0, ) : argument 2 is empty

 plot(x,y, xlim=c(0,NA ))
## Output: Error in plot.window(...) : need finite 'xlim' values

I wish that plot would let me supply just the min (or max) and then calculate the other value where needed.
It is a little bit tedious for the user to do that for herself. The user must be knowledgeable enough to know where the maximum (MAX) is supposed to be, and then supply xlim=c(0, MAX). I can't see any reason for insisting users have that deeper understanding of how R calculates ranges for plots.

Suppose the user is allowed to supply NA to signal R should fill in the blanks.

plot(x,y, xlim=c(0, NA))

In plot.default now, I find this code to manage xlim

   xlim <- if (is.null(xlim))

        range(xy$x[is.finite(xy$x)])

And I would change it to be something like

   ##get default range
   nxlim <- range(xy$x[is.finite(xy$x)])

   ## if xlim is NULL, so same as current     xlim <- if (is.null(xlim)) nxlim
## Otherwise, replace NAs in xlim with values from nxlim

    else xlim[ is.na(xlim) ] <- nxlim[ is.na(xlim) ]

Who is the responsible party for plot.default. How about it?

Think of how much happier users would be!

pj

-- 
Paul E. Johnson
Professor, Political Science    Assoc. Director
1541 Lilac Lane, Room 504     Center for Research Methods
University of Kansas               University of Kansas
http://pj.freefaculty.org            http://quant.ku.edu

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 16 Apr 2012 - 18:11:03 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Mon 16 Apr 2012 - 20:50:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive