[R] I want axes that cross
marc_schwartz at comcast.net
Mon Feb 16 14:15:15 CET 2009
I would also add:
1. Chapter 12 in "An Introduction to R"
2. Chapter 3 in Paul's "R Graphics" book:
Note that the figures and code used for the graphics in the above
chapter are available here:
on 02/16/2009 03:14 AM Mark Difford wrote:
> Hi Paul,
>>> Have you ever seen a drawing of the regions of an R plot with the
>>> terminology that is used for parts?
>>From what I can remember, several documents on CRAN cover this. The one that
> springs to mind is Alzola & Harrell's "An Introduction to S and the Hmisc
> and Design Libraries,” which you can download from the Contributed
> Documentation link on CRAN.
> Chap. 4 of MASS by Venables & Ripley (4th ed.) will also give you what you
> Regards, Mark.
> Paul Johnson-11 wrote:
>> On Fri, Feb 13, 2009 at 3:14 PM, Marc Schwartz
>> <marc_schwartz at comcast.net> wrote:
>>> on 02/13/2009 02:19 PM Paul Johnson wrote:
>>>> On Fri, Feb 13, 2009 at 1:51 PM, Marc Schwartz
>>> OK, so given all of the above, something like the following should work:
>>> x <- rnorm(100)
>>> z <- gl(2,50)
>>> y <- rnorm(100, mean = 1.8 * as.numeric(z))
>>> # Calculate a new range, subtracting a definable value
>>> # from the min of each vector for the new minimum
>>> # Adust the 0.25 as may be needed
>>> X <- c(min(x) - 0.25, max(x))
>>> Y <- c(min(y) - 0.25, max(y))
>>> # Use 'X' and "Y' here, not 'x' and 'y'
>>> # So that the plot region is extended appropriately
>>> plot(X, Y, type = "n", axes = F, xlab = "x", ylab = "y")
>>> points(x, y, pch = "$", cex = 0.7, col = z)
>>> # DO use 'pos'...
>>> axis(1, pos = Y, col = "green", col.axis = "green")
>>> axis(2, pos = X, col = "red", col.axis = "red")
>>> # get the plot region boundaries
>>> usr <- par("usr")
>>> segments(X, usr, X, usr, col = "red")
>>> segments(usr, Y, usr, Y, col = "green")
>> Thanks, Marc and everybody.
>> This last suggestion produces the graph I was trying for.
>> The other approaches that people suggest, using pos or xaxp, produce
>> other undesired changes in the tick marks or the position of the axes
>> relative to the data. xaxp offers the promise of a more intuitive
>> solution, except that, when using it, the tick marks are pushed off in
>> a bad way. Your use of segments to draw the extensions of the axes
>> was the first intuition I had, but I did not know about the trick you
>> used to retrieve the size of the usr box.
>> More secrets of par, revealed.
>> Have you ever seen a drawing of the regions of an R plot with the
>> terminology that is used for parts? Until I saw your example code, I
>> had not understood that the plot axes are placed at the absolute edge
>> of the user plotting region, for example.
More information about the R-help