[R] gap.plot() and axes=F

Jim Lemon jim at bitwrit.com.au
Tue Aug 12 13:33:33 CEST 2008


On Tue, 2008-08-12 at 11:27 +0200, Verena Hoffmann wrote:
> Hello!
> Using the package Plotrix I want to do a plot with a broken axis.
> So far it's working fine but now I want only the x and y axis plotted 
> (the x-axis with a gap in it), but not the axes that are reffered to as 
> axis 3 and 4, and not the lines that additionally mark the gap in the axis.
> I thought an 'axes=F' in the gap.plot() command would do (as in the 
> usual plot()), but it does not.
> The second problem is, that I only can label the ticks before the break 
> in the x-axis.
> 
> That's what I do now:
> library(plotrix)
> a<-c(1,2,3,4,5,6, 51,66,67,68,69)
> b<-c(1,2,3,4,5,6,7,8,9,10,11)
> gap.plot(a,b,gap=c(10,49), gap.axis="x" )
> axis(1, at=c(1,2,3,4,5,6,7,8,9,50,55,60,65,70))
> axis.break(axis=1,9.5,style="slash", brw=0.03, breakcol="red")
> 
Hi Verena,
For the first part, you will have to create your own gap.plot function.
I had a similar question about a week ago, and perhaps the easiest way
is this. Try the following:

library(plotrix)
sink("my.gap.plot.R")
cat("my.gap.plot<-")
gap.plot
sink()

Then open the resulting file "my.gap.plot.R" in a text editor (like
Notepad). On lines 105, 109, 135 and 137 you will find "axis.break"
commands. Change style="gap" to style="slash" in each of these. Save and
then:

source("my.gap.plot.R")

and you should be able to use the function "my.gap.plot" to get slash
style breaks instead of gap style (I don't recommend this, but I'm a
nice guy).

For the second question, just subtract your gap size from the tick
points that are above the gap, e.g.

axis(1,at=c(1:9,11,16,21,26,31))

Hope that fixes your problem.

Jim



More information about the R-help mailing list