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

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

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

PaulJohnson32gmail
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Duncan Murdoch-2
On 12-04-16 1:52 PM, Paul Johnson wrote:
> I'm looking for an R mentor.  I want to propose a change in management
> of plot options xlim and ylim.

Your suggestion sounds reasonable, but because plot limits are such a
commonly used parameter, it would have to be done quite carefully.  The
questions I'd ask before implementing it are:

  - Are there other locations besides plot.default where xlim and ylim
are specified?  I'd like to have them updated consistently.

  - Are there any conflicting uses of NA for a limit in published packages?

  - Which package authors would need to be told about this change, so
they could make a compatible change?

  - Where does it need to be documented?

Duncan Murdoch

>
> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Lorenz, David
In reply to this post by PaulJohnson32gmail
Paul,
  How about
plot(x,y, xlim=c(0, max(pretty(x))))

Dave



From:
Paul Johnson <[hidden email]>
To:
R Devel List <[hidden email]>
Date:
04/16/2012 12:54 PM
Subject:
[Rd] I wish xlim=c(0, NA) would work. How about I send you a patch?
Sent by:
[hidden email]



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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

William Dunlap
In reply to this post by Duncan Murdoch-2
plot(1:10, xlim=c(10,1)) reverses the x axis.
If we allow plot(1:10, xlim=c(5,NA)), which
direction should it go?    Would this require new
parameters, {x,y}{min,max} or new paremeters
{x,y}{axisDirection}?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf
> Of Duncan Murdoch
> Sent: Monday, April 16, 2012 11:14 AM
> To: Paul Johnson
> Cc: R Devel List
> Subject: Re: [Rd] I wish xlim=c(0, NA) would work. How about I send you a patch?
>
> On 12-04-16 1:52 PM, Paul Johnson wrote:
> > I'm looking for an R mentor.  I want to propose a change in management
> > of plot options xlim and ylim.
>
> Your suggestion sounds reasonable, but because plot limits are such a
> commonly used parameter, it would have to be done quite carefully.  The
> questions I'd ask before implementing it are:
>
>   - Are there other locations besides plot.default where xlim and ylim
> are specified?  I'd like to have them updated consistently.
>
>   - Are there any conflicting uses of NA for a limit in published packages?
>
>   - Which package authors would need to be told about this change, so
> they could make a compatible change?
>
>   - Where does it need to be documented?
>
> Duncan Murdoch
>
> >
> > 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Marc Schwartz-3
I would say that Bill's example of reversing the axis range, which I have used many times over the years, along with Duncan's list of potential consequences for a myriad of functions/packages, are arguments against this change.

Classically, R's defaults are generally sensible and if one wants to alter them, it is not unreasonable to expect some understanding of what the arguments are doing. To know how to manipulate a plot's axis ranges is not overly complicated. Knowing that R, by default, will extend them by 4% is arguably a little more subtle, but reading the documentation (eg. ?par) will enlighten one to that point.

To simply use:

  xlim = c(0, max(x))

or

  xlim = c(0, max(x, na.rm = TRUE))

or

  xlim = c(0, max(x[is.finite(x)]))

depending upon what values in x (or y) one might have to worry about, or the reverse for an unknown min and a fixed max, is a reasonable solution to the issue that Paul raises. It is a few more keystrokes than using NA and avoids the myriad known and potentially unanticipated side effects.

Regards,

Marc Schwartz

On Apr 16, 2012, at 1:26 PM, William Dunlap wrote:

> plot(1:10, xlim=c(10,1)) reverses the x axis.
> If we allow plot(1:10, xlim=c(5,NA)), which
> direction should it go?    Would this require new
> parameters, {x,y}{min,max} or new paremeters
> {x,y}{axisDirection}?
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf
>> Of Duncan Murdoch
>> Sent: Monday, April 16, 2012 11:14 AM
>> To: Paul Johnson
>> Cc: R Devel List
>> Subject: Re: [Rd] I wish xlim=c(0, NA) would work. How about I send you a patch?
>>
>> On 12-04-16 1:52 PM, Paul Johnson wrote:
>>> I'm looking for an R mentor.  I want to propose a change in management
>>> of plot options xlim and ylim.
>>
>> Your suggestion sounds reasonable, but because plot limits are such a
>> commonly used parameter, it would have to be done quite carefully.  The
>> questions I'd ask before implementing it are:
>>
>>  - Are there other locations besides plot.default where xlim and ylim
>> are specified?  I'd like to have them updated consistently.
>>
>>  - Are there any conflicting uses of NA for a limit in published packages?
>>
>>  - Which package authors would need to be told about this change, so
>> they could make a compatible change?
>>
>>  - Where does it need to be documented?
>>
>> Duncan Murdoch
>>
>>>
>>> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Duncan Murdoch-2
In reply to this post by William Dunlap
On 12-04-16 2:26 PM, William Dunlap wrote:
> plot(1:10, xlim=c(10,1)) reverses the x axis.
> If we allow plot(1:10, xlim=c(5,NA)), which
> direction should it go?    Would this require new
> parameters, {x,y}{min,max} or new paremeters
> {x,y}{axisDirection}?

I'd rather not add another parameter.  So if I were to implement this,
I'd probably choose Paul's original suggestion.  If someone wants c(5,
NA) to mean c(5, min(data)) rather than c(5, max(data)) they'd need to
code it explicitly.

Duncan Murdoch

>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf
>> Of Duncan Murdoch
>> Sent: Monday, April 16, 2012 11:14 AM
>> To: Paul Johnson
>> Cc: R Devel List
>> Subject: Re: [Rd] I wish xlim=c(0, NA) would work. How about I send you a patch?
>>
>> On 12-04-16 1:52 PM, Paul Johnson wrote:
>>> I'm looking for an R mentor.  I want to propose a change in management
>>> of plot options xlim and ylim.
>>
>> Your suggestion sounds reasonable, but because plot limits are such a
>> commonly used parameter, it would have to be done quite carefully.  The
>> questions I'd ask before implementing it are:
>>
>>    - Are there other locations besides plot.default where xlim and ylim
>> are specified?  I'd like to have them updated consistently.
>>
>>    - Are there any conflicting uses of NA for a limit in published packages?
>>
>>    - Which package authors would need to be told about this change, so
>> they could make a compatible change?
>>
>>    - Where does it need to be documented?
>>
>> Duncan Murdoch
>>
>>>
>>> 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
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Henrik Bengtsson-3
Reversing the direction of an axis currently needs an explicit 'xlim'
such that diff(xlim) < 0 [I think].  Thus, the assumption to do a
"forward" plot when "leaving out" one element in 'xlim' by setting it
to a missing value is not too bad.

However, what about using +Inf and -Inf as instead?  Disclaimer: I
haven't bumped into one, but it could be that there plot functions
that include -Inf/+Inf.  Example:

## Case #1: Infer 2nd argument in 'xlim' from data
# (a) Forward
plot(x, xlim=c(0,+Inf))
# (b) Reverse
plot(x, xlim=c(0,-Inf))

## Case #2: Infer 1st argument in 'xlim' from data
# (a) Forward
plot(x, xlim=c(-Inf,0))
# (b) Reverse
plot(x, xlim=c(+Inf,0))

## Case #3: Infer both arguments in 'xlim' from data
# (a) Forward
plot(x, xlim=c(-Inf,+Inf))
# (b) Reverse
plot(x, xlim=c(+Inf,-Inf))

Note how the latter also supports a use case currently not supported.

/Henrik


On Mon, Apr 16, 2012 at 12:15 PM, Duncan Murdoch
<[hidden email]> wrote:

> On 12-04-16 2:26 PM, William Dunlap wrote:
>>
>> plot(1:10, xlim=c(10,1)) reverses the x axis.
>> If we allow plot(1:10, xlim=c(5,NA)), which
>> direction should it go?    Would this require new
>> parameters, {x,y}{min,max} or new paremeters
>> {x,y}{axisDirection}?
>
>
> I'd rather not add another parameter.  So if I were to implement this, I'd
> probably choose Paul's original suggestion.  If someone wants c(5, NA) to
> mean c(5, min(data)) rather than c(5, max(data)) they'd need to code it
> explicitly.
>
> Duncan Murdoch
>
>
>>
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com
>>
>>
>>> -----Original Message-----
>>> From: [hidden email]
>>> [mailto:[hidden email]] On Behalf
>>> Of Duncan Murdoch
>>> Sent: Monday, April 16, 2012 11:14 AM
>>> To: Paul Johnson
>>> Cc: R Devel List
>>> Subject: Re: [Rd] I wish xlim=c(0, NA) would work. How about I send you a
>>> patch?
>>>
>>> On 12-04-16 1:52 PM, Paul Johnson wrote:
>>>>
>>>> I'm looking for an R mentor.  I want to propose a change in management
>>>> of plot options xlim and ylim.
>>>
>>>
>>> Your suggestion sounds reasonable, but because plot limits are such a
>>> commonly used parameter, it would have to be done quite carefully.  The
>>> questions I'd ask before implementing it are:
>>>
>>>   - Are there other locations besides plot.default where xlim and ylim
>>> are specified?  I'd like to have them updated consistently.
>>>
>>>   - Are there any conflicting uses of NA for a limit in published
>>> packages?
>>>
>>>   - Which package authors would need to be told about this change, so
>>> they could make a compatible change?
>>>
>>>   - Where does it need to be documented?
>>>
>>> Duncan Murdoch
>>>
>>>>
>>>> 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
>>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

glsnow
In reply to this post by PaulJohnson32gmail
The simple work around is to use the range function, if you use
something like:  xlim=range(0,x) then 0 will be included in the range
of the x axis (and if there are values less than 0 then those values
will be included as well) and the max is computed from the data as
usual.  The range function will also accept multiple vectors and make
the range big enough to include all of them on the plot (this is what
I use when I will be adding additional information using points or
lines).

With this functionality in range I don't really see much need for the
proposed change, maybe an example on the plot help page to show this
would suffice.

On Mon, Apr 16, 2012 at 11:52 AM, Paul Johnson <[hidden email]> wrote:

> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



--
Gregory (Greg) L. Snow Ph.D.
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

baptiste auguie-5
Hi,

Using range wouldn't help if you wanted to restrict one of the limits,
not stretch it

plot(1:11, y <- seq(-5, 5), ylim= range(0, y))

baptiste

On 17 April 2012 08:20, Greg Snow <[hidden email]> wrote:

> The simple work around is to use the range function, if you use
> something like:  xlim=range(0,x) then 0 will be included in the range
> of the x axis (and if there are values less than 0 then those values
> will be included as well) and the max is computed from the data as
> usual.  The range function will also accept multiple vectors and make
> the range big enough to include all of them on the plot (this is what
> I use when I will be adding additional information using points or
> lines).
>
> With this functionality in range I don't really see much need for the
> proposed change, maybe an example on the plot help page to show this
> would suffice.
>
> On Mon, Apr 16, 2012 at 11:52 AM, Paul Johnson <[hidden email]> wrote:
>> 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
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Kasper Daniel Hansen-2
On Mon, Apr 16, 2012 at 4:29 PM, baptiste auguie
<[hidden email]> wrote:
> Hi,
>
> Using range wouldn't help if you wanted to restrict one of the limits,
> not stretch it
>
> plot(1:11, y <- seq(-5, 5), ylim= range(0, y))

range(pmin(0,y))

Kasper


>
> baptiste
>
> On 17 April 2012 08:20, Greg Snow <[hidden email]> wrote:
>> The simple work around is to use the range function, if you use
>> something like:  xlim=range(0,x) then 0 will be included in the range
>> of the x axis (and if there are values less than 0 then those values
>> will be included as well) and the max is computed from the data as
>> usual.  The range function will also accept multiple vectors and make
>> the range big enough to include all of them on the plot (this is what
>> I use when I will be adding additional information using points or
>> lines).
>>
>> With this functionality in range I don't really see much need for the
>> proposed change, maybe an example on the plot help page to show this
>> would suffice.
>>
>> On Mon, Apr 16, 2012 at 11:52 AM, Paul Johnson <[hidden email]> wrote:
>>> 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
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> [hidden email]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

MacQueen, Don
In reply to this post by Duncan Murdoch-2
Another potential problem with the xlim=c(5,NA) type of approach is
that if I am calculating the limits (as I often do) and have a bug
in my calculation, such that I get an NA for one of the limits,
then my plot would succeed rather than fail -- and succeed with
hard to predict results. This will make it harder for me to
discover my bug, I think.

Where this potential problem lies in a scale of "seriousness" relative
to other potential problems ... I have no idea.

-Don

--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 4/16/12 12:15 PM, "Duncan Murdoch" <[hidden email]> wrote:

>On 12-04-16 2:26 PM, William Dunlap wrote:
>> plot(1:10, xlim=c(10,1)) reverses the x axis.
>> If we allow plot(1:10, xlim=c(5,NA)), which
>> direction should it go?    Would this require new
>> parameters, {x,y}{min,max} or new paremeters
>> {x,y}{axisDirection}?
>
>I'd rather not add another parameter.  So if I were to implement this,
>I'd probably choose Paul's original suggestion.  If someone wants c(5,
>NA) to mean c(5, min(data)) rather than c(5, max(data)) they'd need to
>code it explicitly.
>
>Duncan Murdoch
>
>>
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com
>>
>>
>>> -----Original Message-----
>>> From: [hidden email]
>>>[mailto:[hidden email]] On Behalf
>>> Of Duncan Murdoch
>>> Sent: Monday, April 16, 2012 11:14 AM
>>> To: Paul Johnson
>>> Cc: R Devel List
>>> Subject: Re: [Rd] I wish xlim=c(0, NA) would work. How about I send
>>>you a patch?
>>>
>>> On 12-04-16 1:52 PM, Paul Johnson wrote:
>>>> I'm looking for an R mentor.  I want to propose a change in management
>>>> of plot options xlim and ylim.
>>>
>>> Your suggestion sounds reasonable, but because plot limits are such a
>>> commonly used parameter, it would have to be done quite carefully.  The
>>> questions I'd ask before implementing it are:
>>>
>>>    - Are there other locations besides plot.default where xlim and ylim
>>> are specified?  I'd like to have them updated consistently.
>>>
>>>    - Are there any conflicting uses of NA for a limit in published
>>>packages?
>>>
>>>    - Which package authors would need to be told about this change, so
>>> they could make a compatible change?
>>>
>>>    - Where does it need to be documented?
>>>
>>> Duncan Murdoch
>>>
>>>>
>>>> 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
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

ghostwheel
In reply to this post by glsnow
I have also often longed for such a shortcut.

The problem is that most often, my plot statements do not look like this:
plot(y)

but instead like this:
plot( some_very_long_expression_involving(x), some_other_very_long_expression_involving(x) )

And since I'm working with a GUI, I often go up and change this or that expression.
Then it starts to be ugly to have to work with range(pretty(ugly_expressions())). Of course, I could always do
x=some_very_long_expression, y=some_other_very_long_expression; plot(x,y)

Another possible solution would be to use:
plot(x,y, ylim=c(min=9) )
in order to identify which limit I'd like to set. That shouldn't usually mess up anything, right?

Michael
Reply | Threaded
Open this post in threaded view
|

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

ghostwheel
The following seems to work well, and I don't think it'll break anything.
The only problem I see is if someone says xlim=c(min=9, max=0), which should give an error/warning message, but won't.

Michael
---
plot.default=
function (x, y = NULL, type = "p", xlim = NULL, ylim = NULL,
      log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
      ann = par("ann"), axes = TRUE, frame.plot = axes, panel.first = NULL,
      panel.last = NULL, asp = NA, ...)
  {
        localAxis <- function(..., col, bg, pch, cex, lty, lwd) Axis(...)
            localBox <- function(..., col, bg, pch, cex, lty, lwd) box(...)
            localWindow <- function(..., col, bg, pch, cex, lty, lwd) plot.window(...)
            localTitle <- function(..., col, bg, pch, cex, lty, lwd) title(...)
            xlabel <- if (!missing(x))
                      deparse(substitute(x))
            ylabel <- if (!missing(y))
                      deparse(substitute(y))
            xy <- xy.coords(x, y, xlabel, ylabel, log)
            xlab <- if (is.null(xlab))
                      xy$xlab
            else xlab
            ylab <- if (is.null(ylab))
                      xy$ylab
            else ylab
            xlim <- if (is.null(xlim))
                      range(xy$x[is.finite(xy$x)])
            else if( length(xlim)==1 & names(xlim)=="min" ) {
              c(xlim,range(xy$x[is.finite(xy$x)])[2]) }
            else if( length(xlim)==1 & names(xlim)=="max" ) {
              c( range(xy$x[is.finite(xy$x)])[1], xlim) }        
        else xlim
        ylim <- if (is.null(ylim))
                      range(xy$y[is.finite(xy$y)])
            else if( length(ylim)==1 & names(ylim)=="min" ) {
              c( ylim,range(xy$y[is.finite(xy$y)])[2]) }
            else if( length(ylim)==1 & names(ylim)=="max" ) {
              c( range(xy$y[is.finite(xy$y)])[1], ylim) }        
            else ylim
            dev.hold()
            on.exit(dev.flush())
            plot.new()
            localWindow(xlim, ylim, log, asp, ...)
            panel.first
            plot.xy(xy, type, ...)
            panel.last
            if (axes) {
                      localAxis(if (is.null(y))
                                            xy$x
                                        else x, side = 1, ...)
                              localAxis(if (is.null(y))
                                                    x
                                                else y, side = 2, ...)
                    }
            if (frame.plot)
                      localBox(...)
            if (ann)
                      localTitle(main = main, sub = sub, xlab = xlab, ylab = ylab,
                                             ...)
            invisible()
      }
Reply | Threaded
Open this post in threaded view
|

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

ghostwheel
Sorry, the previous had a bug and was quite ugly. This is a bit better:
--
function (x, y = NULL, type = "p", xlim = NULL, ylim = NULL,
      log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
      ann = par("ann"), axes = TRUE, frame.plot = axes, panel.first = NULL,
      panel.last = NULL, asp = NA, ...)
  {
        localAxis <- function(..., col, bg, pch, cex, lty, lwd) Axis(...)
            localBox <- function(..., col, bg, pch, cex, lty, lwd) box(...)
            localWindow <- function(..., col, bg, pch, cex, lty, lwd) plot.window(...)
            localTitle <- function(..., col, bg, pch, cex, lty, lwd) title(...)
            xlabel <- if (!missing(x))
                      deparse(substitute(x))
            ylabel <- if (!missing(y))
                      deparse(substitute(y))
            xy <- xy.coords(x, y, xlabel, ylabel, log)
            xlab <- if (is.null(xlab))
                      xy$xlab
            else xlab
            ylab <- if (is.null(ylab))
                      xy$ylab
            else ylab
            xlim <- if (is.null(xlim))
                      range(xy$x[is.finite(xy$x)])
        else if( length(xlim)==1 ) {
          xlim.in=xlim
          xlim = range(xy$x[is.finite(xy$x)])
          xlim[pmatch( names(xlim.in),c("min","max") )] = xlim.in
          xlim
        } else xlim
        ylim <- if (is.null(ylim))
                      range(xy$y[is.finite(xy$y)])
            else  if( length(ylim)==1 ) {
          ylim.in=ylim
          ylim = range(xy$y[is.finite(xy$y)])
          ylim[pmatch( names(ylim.in),c("min","max") )] = ylim.in
          ylim
        }   else ylim
            dev.hold()
            on.exit(dev.flush())
            plot.new()
            localWindow(xlim, ylim, log, asp, ...)
            panel.first
            plot.xy(xy, type, ...)
            panel.last
            if (axes) {
                      localAxis(if (is.null(y))
                                            xy$x
                                        else x, side = 1, ...)
                              localAxis(if (is.null(y))
                                                    x
                                                else y, side = 2, ...)
                    }
            if (frame.plot)
                      localBox(...)
            if (ann)
                      localTitle(main = main, sub = sub, xlab = xlab, ylab = ylab,
                                             ...)
            invisible()
      }
--