[R] adding custom axis to image.plot() and strange clipping behavior
kate at few.vu.nl
Fri Jun 13 12:12:29 CEST 2008
I also noticed that adding a custom axis with image.plot was a problem;
you can also do:
m <- matrix(1:15,ncol=3)
##### add axis
## add legend
On Fri, 13 Jun 2008, Stephen Tucker wrote:
> Hi list,
> I wanted to plot an image with a colorbar to the right of the plot, but
> set my own axis labels (text rather than numbers) to the image. I have
> previously accomplished this with two calls to image(), but the package
> 'fields' has a wrapper function, image.plot(), which does this task
> However, I could not add axes to the original image after a call to
> image.plot(); I have found that I needed to set par(xpd=TRUE) within the
> function to allow this to happen:
> ###=== begin code
> ## make data matrix
> m <- matrix(1:15,ncol=3)
> ## plot
> axis(1) # doesn't work
> axis(1) # still doesn't work
> ## replace the 28th element of the body of image.plot()
> ## and assign to new function called 'imp'
> ## here I just use the second condition of 'if' statement
> ## and set 'xpd = TRUE'
> imp <- `body<-`(image.plot,value=`[[<-`(body(image.plot),28,
> par(plt = big.par$plt, xpd = TRUE)
> par(mfg = mfg.save, new = FALSE)
> ## clip to plotting region for additional
> ## graphical elements to be added:
> ###=== end code
> I wonder if anyone has any insights into this behavior? Since in the axis() documentation, it says:
> "Note that xpd is not accepted as clipping is always to the device region"
> I am surprised to find (1) that the par(xpd=TRUE) works in the case above, and (2) that it must be called before the function call is terminated.
> I wonder if anyone has any insights into this behavior. I have reproduced this on both my Linux box (Ubuntu Gutsy Gibbon 64-bit, R 2.7.0, fields package version 4.1) and Windows machine (32-bit XP Pro, R 2.7.0, fields package version 4.1).
> Thanks very much,
> R-help at r-project.org mailing list
> 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