[R] plot changes usr?

William Dunlap wdunlap at tibco.com
Tue Sep 29 18:31:23 CEST 2015


If you want to set the axis limits to exactly your given xlim and ylim, also use
xaxs="i" and yaxs="i" (x or y "axis style" is "internal") in your plot
command.  E.g.,

 plot(xaxs="i", yaxs="i", 1:10, 87:96, xlim=c(-0.75, 13.2), ylim=c(81.03,100.2))
 par("usr")
 #[1]  -0.75  13.20  81.03 100.20

as compared to

 plot(1:10, 87:96, xlim=c(-0.75, 13.2), ylim=c(81.03,100.2))
 par("usr")
 #[1]  -1.3080  13.7580  80.2632 100.9668

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Sep 28, 2015 at 11:53 PM, Jim Lemon <drjimlemon at gmail.com> wrote:
> Hi Ed,
> While David's suggestion is correct, the change in par("usr") results from
> your resetting the plot limits.
>
> data(mtcars)
> plot(mtcars$mpg, mtcars$hp)
> par("usr")
> [1]   9.46  34.84  40.68 346.32
> par(new=TRUE)
> plot(mtcars$mpg, mtcars$hp,col="red",axes=FALSE)
> par("usr")
> [1]   9.46  34.84  40.68 346.32
>
> Jim
>
> On Tue, Sep 29, 2015 at 10:57 AM, David Winsemius <dwinsemius at comcast.net>
> wrote:
>
>>
>> On Sep 28, 2015, at 5:33 PM, Ed Siefker wrote:
>>
>> > I'm trying to plot() over an existing plot() like this:
>> >
>> >> attach(mtcars)
>> >> plot(mpg, hp)
>> >> par(new=TRUE)
>> >> par("usr")
>> > [1]   9.46  34.84  40.68 346.32
>> >> plot(mpg, hp, col="red", axes=FALSE, xlim=par("usr")[1:2],
>> ylim=par("usr")[3:4], xlab="", ylab="")
>> >> par("usr")
>> > [1]   8.4448  35.8552  28.4544 358.5456
>>
>> The default usr ranges are some factor (my hazy memory says 104%) of the
>> range of thex- and y-values unless you specify otherwise. This choice
>> allows round data-points to be displayed at the extremes. Why are you
>> trying to muck with the plot setup? The right way would be to use points().
>>
>>
>> >
>> > For some reason "usr" is changing, and so it's not plotting over the
>> > existing data in the right place.
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list