Thanks for the advice!  It has worked for the most part.  However, I am
still coming up with an error message when placing my break line in the axis
that I'm not sure what it means.  If you could help me out, that would be
fantastic...otherwise I might just have to see if I can add it on
powerpoint.  Here is the code you gave me and my script that doesn't work.
*
*#your script
*axis.break<-function(axis=1,*
*breakpos=NULL,pos=NA,bgcol="**white",breakcol="black",
 style="slash",brw=0.02) {

 # get the coordinates of the outside of the plot
 figxy<-par("usr")
 # flag if either axis is logarithmic
 xaxl<-par("xlog")
 yaxl<-par("ylog")
 # calculate the x and y offsets for the break
 xw<-(figxy[2]-figxy[1])*brw
 yw<-(figxy[4]-figxy[3])*brw
 if(!is.na(pos)) figxy<-rep(pos,4)
 # if no break position was given, put it just off the plot origin
 if(is.null(breakpos))
  breakpos<-ifelse(axis%%2,**figxy[1]+xw*2,figxy[3]+yw*2)
 if(xaxl && (axis == 1 || axis == 3)) breakpos<-log10(breakpos)
 if(yaxl && (axis == 2 || axis == 4)) breakpos<-log10(breakpos)
 # set up the "blank" rectangle (left, bottom, right, top)
 switch(axis,
  br<-c(breakpos-xw/2,figxy[3]-**yw/2,breakpos+xw/2,figxy[3]+**yw/2),
  br<-c(figxy[1]-xw/2,breakpos-**yw/2,figxy[1]+xw/2,breakpos+**yw/2),
  br<-c(breakpos-xw/2,figxy[4]-**yw/2,breakpos+xw/2,figxy[4]+**yw/2),
  br<-c(figxy[2]-xw/2,breakpos-**yw/2,figxy[2]+xw/2,breakpos+**yw/2),
  stop("Improper axis specification."))
 # get the current setting of xpd
 old.xpd<-par("xpd")
 # don't cut the break off at the edge of the plot
 par(xpd=TRUE)
 # correct for logarithmic axes
 if(xaxl) br[c(1,3)]<-10^br[c(1,3)]
 if(yaxl) br[c(2,4)]<-10^br[c(2,4)]
 if(style == "gap") {
  if(xaxl) {
   figxy[1]<-10^figxy[1]
   figxy[2]<-10^figxy[2]
  }
  if(yaxl) {
   figxy[3]<-10^figxy[3]
   figxy[4]<-10^figxy[4]
  }
  # blank out the gap area and calculate the line segments
  if(axis == 1 || axis == 3) {
   rect(breakpos,figxy[3],**breakpos+xw,figxy[4],col=**bgcol,border=bgcol)
   xbegin<-c(breakpos,breakpos+**xw)
   ybegin<-c(figxy[3],figxy[3])
   xend<-c(breakpos,breakpos+xw)
   yend<-c(figxy[4],figxy[4])
   if(xaxl) {
    xbegin<-10^xbegin
    xend<-10^xend
   }
  }
  else {
   rect(figxy[1],breakpos,figxy[**2],breakpos+yw,col=bgcol,**border=bgcol)
   xbegin<-c(figxy[1],figxy[1])
   ybegin<-c(breakpos,breakpos+**yw)
   xend<-c(figxy[2],figxy[2])
   yend<-c(breakpos,breakpos+yw)
   if(xaxl) {
    xbegin<-10^xbegin
    xend<-10^xend
   }
  }
  # clip the lines
  par(xpd=TRUE)
 }
 else {
  # draw the "blank" rectangle
  rect(br[1],br[2],br[3],br[4],**col=bgcol,border=bgcol)
  if(style == "slash") {
   # calculate the slash ends
   if(axis == 1 || axis == 3) {
    xbegin<-c(breakpos-xw,**breakpos)
    xend<-c(breakpos,breakpos+xw)
    ybegin<-c(br[2],br[2])
    yend<-c(br[4],br[4])
    if(xaxl) {
     xbegin<-10^xbegin
     xend<-10^xend
    }
   }
   else {
    xbegin<-c(br[1],br[1])
    xend<-c(br[3],br[3])
    ybegin<-c(breakpos-yw,**breakpos)
    yend<-c(breakpos,breakpos+yw)
    if(yaxl) {
     ybegin<-10^ybegin
     yend<-10^yend
    }
   }
  }
  else {
   # calculate the zigzag ends
   if(axis == 1 || axis == 3) {
    xbegin<-c(breakpos-xw/2,**breakpos-xw/4,breakpos+xw/4)
    xend<-c(breakpos-xw/4,**breakpos+xw/4,breakpos+xw/2)
    
ybegin<-c(ifelse(yaxl,10^**figxy[3+(axis==3)],figxy[3+(**axis==3)]),br[4],br[2])

    
yend<-c(br[4],br[2],ifelse(**yaxl,10^figxy[3+(axis==3)],**figxy[3+(axis==3)]))

    if(xaxl) {
     xbegin<-10^xbegin
     xend<-10^xend
    }
   }
   else {
    
xbegin<-c(ifelse(xaxl,10^**figxy[1+(axis==4)],figxy[1+(**axis==4)]),br[1],br[3])

    
xend<-c(br[1],br[3],ifelse(**xaxl,10^figxy[1+(axis==4)],**figxy[1+(axis==4)]))

    ybegin<-c(breakpos-yw/2,**breakpos-yw/4,breakpos+yw/4)
    yend<-c(breakpos-yw/4,**breakpos+yw/4,breakpos+yw/2)
    if(yaxl) {
     ybegin<-10^ybegin
     yend<-10^yend
    }
   }
  }
 }
 # draw the segments
 segments(xbegin,ybegin,xend,**yend,col=breakcol,lty=1)
 # restore xpd
 par(xpd=FALSE)
} *

#my script
*library(plotrix)

par(mar=c(6,8,4,4))
par(xpd=TRUE)

Saline <- structure(list(Time = c(-20L, 0, 30L, 45L, 60L, 80L, 110L,
140L,200L, 260L, 320L), Average =
c(119.250,118.750,117.500,132.75,151.875,159.75,142.75,160,168,167.125,143),SEM
=
c(2.211,2.569,2.665,5.435146394,6.208741369,8.363550657,8.51349469,14.30284687,15.93865792,16.76541326,13.796)),
.Names = c("Time (min)",
"Arterial Plasma Glucose (µg/mL)", "SEM"), class = "data.frame", row.names =
c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11"))

plotCI(x=Saline [,1],y=Saline [,2]-80, uiw=Saline [,3], err="y",
  pt.bg=par("bg"),pch=19, cex=2.5 ,gap=0, sfrac=0.005,
 xlim=c(-20,340),xaxp=c(-20,320,12), xlab="Time (min)", ylim=c(0,100),
  yaxp=c(0,100,10), ylab="Arterial Plasma\nGlucose (µg/mL)", las=1,
axes=FALSE,
 font.lab=2.2,cex.lab=1.6)

 Ex <- structure(list(Time = c(-20L, 0, 30L, 45L, 60L, 80L, 110L, 140L,
200L, 260L, 320L), Average =
c(117.500,117.625,117.375,134.5,166.25,173.5,164.25,162.5,160.375,150.25,139.875),
    SEM =
c(1.484614978,1.748906364,1.761,5.613395058,9.642063459,9.493284415,8.220804866,8.967059901,11.91626825,11.27169111,10.92915498)),
.Names = c("Time (min)",
 "Arterial Plasma Glucose (µg/mL)", "SEM"), class = "data.frame", row.names
= c("1", "2",
 "3", "4", "5", "6", "7", "8", "9", "10", "11"))

plotCI(x=Ex [,1],y=Ex [,2]-80, uiw=Ex [,3], err="y",
pt.bg="white",pch=21, col="black",cex=2.5 ,gap=0, sfrac=0.005,
 xlim=c(-20,340),xaxp=c(-20,320,12), xlab="Time (min)", ylim=c(0,100),
  yaxp=c(0,100,10), ylab="Arterial Plasma\nGlucose (µg/mL)", las=1,
font.lab=2.2, axes=FALSE,
add=TRUE, cex.lab=1.9)

axis(1, at=c("-20", "0", "30", "45", "60", "80", "110", "140", "200", "260",
"320"), lwd=2, font=2, pos=0,cex.axis=.9)
axis(2, las=1, at=c("0", "20", "40", "60", "80", "100","120"), labels=c("0",
"100", "120", "140", "160", "180","200"), lwd=2, font=2, pos="-20",
cex.axis=1.7)
axis.break(axis=2, breakpos=50,style="slash",pos="-20",brw=0.02)*

I keep getting the following error message:

Error in figxy[1] - xw/2 : non-numeric argument to binary operator

and I am unsure of what exactly that means or how to fix it.  Any help would
be much appreciated.  Thank you in advance, your help has been absolutely
invaluable.

beloitstudent


On Sun, Jun 13, 2010 at 6:46 AM, Jim Lemon [via R] <
ml-node+2253367-963602117-278...@n4.nabble.com<ml-node%2b2253367-963602117-278...@n4.nabble.com>
> wrote:

> On 06/13/2010 01:48 PM, beloitstudent wrote:
>
> >
> > Hello all,
> >
> > I have been having trouble getting a break in my y-axis.  All of my data
> > points are up around 100-200, but the graph has to start at zero, so i
> would
> > like to remove all the white space using a break symbol.  I have been
> able
> > to get the break and labels to be correct, however, I can't seem to get
> the
> > data to match the axis anymore.  I must be using the axis.break() in
> plotrix
> > incorrectly, but I cannot see where my issue is.  This is what I have so
> > far.
> >
> > ######
> > library(plotrix)
> >
> > par(mar=c(6,8,4,4))
> > ###Data
> > Saline<- structure(list(Time = c(-20L, 0, 30L, 45L, 60L, 80L,
> > 110L,140L,200L, 260L, 320L), Average =
> >
> c(119.250,118.750,117.500,132.75,151.875,159.75,142.75,160,168,167.125,143),SEM=c(2.211,2.569,2.665,5.435146394,6.208741369,8.363550657,8.51349469,14.30284687,15.93865792,16.76541326,13.796)),
>
> > .Names = c("Time (min)", "Arterial Plasma Glucose (µg/mL)", "SEM"), class
> =
> > "data.frame", row.names = c("1", "2","3", "4", "5", "6", "7", "8", "9",
> > "10", "11"))
> >
> > Ex<- structure(list(Time = c(-20L, 0, 30L, 45L, 60L, 80L, 110L,140L,200L,
>
> > 260L, 320L), Average =
> >
> c(117.500,117.625,117.375,134.5,166.25,173.5,164.25,162.5,160.375,150.25,139.875),SEM
>
> > =
> >
> c(1.484614978,1.748906364,1.761,5.613395058,9.642063459,9.493284415,8.220804866,8.967059901,11.91626825,11.27169111,10.92915498)),
>
> > .Names = c("Time (min)", "Arterial Plasma Glucose (µg/mL)", "SEM"), class
> =
> > "data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
> > "10", "11"))
> >
> > ####plotted data with error bars
> > plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], err="y",
> > pt.bg=par("bg"),pch=19, cex=2.5 ,gap=0, sfrac=0.005,
> > xlim=c(-20,340),xaxp=c(-20,320,12), xlab="Time (min)",
> > ylim=c(0,200),yaxp=c(0,200,10), ylab="Arterial Plasma\nGlucose (µg/mL)",
> > las=1, axes=FALSE, font.lab=2.2,cex.lab=1.6)
> >
> > plotCI(x=Ex [,1],y=Ex [,2], uiw=Ex [,3], err="y",pt.bg="white",pch=21,
> > col="black",cex=2.5 ,gap=0, sfrac=0.005,
> xlim=c(-20,340),xaxp=c(-20,320,12),
> > xlab="Time (min)", ylim=c(0,200),  yaxp=c(0,200,10), ylab="Arterial
> > Plasma\nGlucose (µg/mL)", las=1, font.lab=2.2, axes=FALSE, add=TRUE,
> > cex.lab=1.9)
> >
> > ##########x-axis
> > axis(1, at=c("-20", "0", "30", "45", "60", "80", "110", "140", "200",
> "260",
> > "320"), lwd=2, font=2, pos=0,cex.axis=.9)
> >
> > ########y-axis
> > axis(2, las=1, at=c(0,40,60,80,100,120, 140), labels=c("0", "100", "120",
>
> > "140", "160", "180", "200"), lwd=2, font=2, pos="-20", cex.axis=1.7)
> >
> > #####axis break
> > axis.break(2, 20, style="slash")
> >
> >
> > As you can see, my data does not fit my axis anymore.  Any help with this
>
> > problem would be fantastic.  Thanks!
> >
> Hi beloitstudent,
> You have two problems here. First, if you want the plotted values to
> match the offset labels on the y-axis, you are going to have to apply
> the same offset to the y values.
>
> plotCI(x=Saline [,1],y=Saline [,2]-60,...
> plotCI(x=Ex [,1],y=Ex [,2]-60,...
>
> The other problem is mine, I guess. I hadn't thought of offset axes when
> writing axis.break, so I've added an argument for "pos" as in the axis
> function. The modified function is attached, and will be in the next
> version of plotrix. Thanks for bringing my attention to this.
>
> Jim
>
>
> # axis.break places a break marker at the position "breakpos"
> # in user coordinates on the axis nominated - see axis().
>
> axis.break<-function(axis=1,breakpos=NULL,pos=NA,bgcol="white",breakcol="black",
>
>  style="slash",brw=0.02) {
>
>  # get the coordinates of the outside of the plot
>  figxy<-par("usr")
>  # flag if either axis is logarithmic
>  xaxl<-par("xlog")
>  yaxl<-par("ylog")
>  # calculate the x and y offsets for the break
>  xw<-(figxy[2]-figxy[1])*brw
>  yw<-(figxy[4]-figxy[3])*brw
>  if(!is.na(pos)) figxy<-rep(pos,4)
>  # if no break position was given, put it just off the plot origin
>  if(is.null(breakpos))
>   breakpos<-ifelse(axis%%2,figxy[1]+xw*2,figxy[3]+yw*2)
>  if(xaxl && (axis == 1 || axis == 3)) breakpos<-log10(breakpos)
>  if(yaxl && (axis == 2 || axis == 4)) breakpos<-log10(breakpos)
>  # set up the "blank" rectangle (left, bottom, right, top)
>  switch(axis,
>   br<-c(breakpos-xw/2,figxy[3]-yw/2,breakpos+xw/2,figxy[3]+yw/2),
>   br<-c(figxy[1]-xw/2,breakpos-yw/2,figxy[1]+xw/2,breakpos+yw/2),
>   br<-c(breakpos-xw/2,figxy[4]-yw/2,breakpos+xw/2,figxy[4]+yw/2),
>   br<-c(figxy[2]-xw/2,breakpos-yw/2,figxy[2]+xw/2,breakpos+yw/2),
>   stop("Improper axis specification."))
>  # get the current setting of xpd
>  old.xpd<-par("xpd")
>  # don't cut the break off at the edge of the plot
>  par(xpd=TRUE)
>  # correct for logarithmic axes
>  if(xaxl) br[c(1,3)]<-10^br[c(1,3)]
>  if(yaxl) br[c(2,4)]<-10^br[c(2,4)]
>  if(style == "gap") {
>   if(xaxl) {
>    figxy[1]<-10^figxy[1]
>    figxy[2]<-10^figxy[2]
>   }
>   if(yaxl) {
>    figxy[3]<-10^figxy[3]
>    figxy[4]<-10^figxy[4]
>   }
>   # blank out the gap area and calculate the line segments
>   if(axis == 1 || axis == 3) {
>    rect(breakpos,figxy[3],breakpos+xw,figxy[4],col=bgcol,border=bgcol)
>    xbegin<-c(breakpos,breakpos+xw)
>    ybegin<-c(figxy[3],figxy[3])
>    xend<-c(breakpos,breakpos+xw)
>    yend<-c(figxy[4],figxy[4])
>    if(xaxl) {
>     xbegin<-10^xbegin
>     xend<-10^xend
>    }
>   }
>   else {
>    rect(figxy[1],breakpos,figxy[2],breakpos+yw,col=bgcol,border=bgcol)
>    xbegin<-c(figxy[1],figxy[1])
>    ybegin<-c(breakpos,breakpos+yw)
>    xend<-c(figxy[2],figxy[2])
>    yend<-c(breakpos,breakpos+yw)
>    if(xaxl) {
>     xbegin<-10^xbegin
>     xend<-10^xend
>    }
>   }
>   # clip the lines
>   par(xpd=TRUE)
>  }
>  else {
>   # draw the "blank" rectangle
>   rect(br[1],br[2],br[3],br[4],col=bgcol,border=bgcol)
>   if(style == "slash") {
>    # calculate the slash ends
>    if(axis == 1 || axis == 3) {
>     xbegin<-c(breakpos-xw,breakpos)
>     xend<-c(breakpos,breakpos+xw)
>     ybegin<-c(br[2],br[2])
>     yend<-c(br[4],br[4])
>     if(xaxl) {
>      xbegin<-10^xbegin
>      xend<-10^xend
>     }
>    }
>    else {
>     xbegin<-c(br[1],br[1])
>     xend<-c(br[3],br[3])
>     ybegin<-c(breakpos-yw,breakpos)
>     yend<-c(breakpos,breakpos+yw)
>     if(yaxl) {
>      ybegin<-10^ybegin
>      yend<-10^yend
>     }
>    }
>   }
>   else {
>    # calculate the zigzag ends
>    if(axis == 1 || axis == 3) {
>     xbegin<-c(breakpos-xw/2,breakpos-xw/4,breakpos+xw/4)
>     xend<-c(breakpos-xw/4,breakpos+xw/4,breakpos+xw/2)
>
> ybegin<-c(ifelse(yaxl,10^figxy[3+(axis==3)],figxy[3+(axis==3)]),br[4],br[2])
>
>
> yend<-c(br[4],br[2],ifelse(yaxl,10^figxy[3+(axis==3)],figxy[3+(axis==3)]))
>     if(xaxl) {
>      xbegin<-10^xbegin
>      xend<-10^xend
>     }
>    }
>    else {
>
> xbegin<-c(ifelse(xaxl,10^figxy[1+(axis==4)],figxy[1+(axis==4)]),br[1],br[3])
>
>
> xend<-c(br[1],br[3],ifelse(xaxl,10^figxy[1+(axis==4)],figxy[1+(axis==4)]))
>     ybegin<-c(breakpos-yw/2,breakpos-yw/4,breakpos+yw/4)
>     yend<-c(breakpos-yw/4,breakpos+yw/4,breakpos+yw/2)
>     if(yaxl) {
>      ybegin<-10^ybegin
>      yend<-10^yend
>     }
>    }
>   }
>  }
>  # draw the segments
>  segments(xbegin,ybegin,xend,yend,col=breakcol,lty=1)
>  # restore xpd
>  par(xpd=FALSE)
> }
>
> ______________________________________________
> [hidden email] <http://user/SendEmail.jtp?type=node&node=2253367&i=0>mailing 
> list
> 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.
>
>
> ------------------------------
>  View message @
> http://r.789695.n4.nabble.com/Break-in-the-y-axis-tp2253205p2253367.html
> To unsubscribe from Break in the y-axis, click here< (link removed) ==>.
>
>
>

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Break-in-the-y-axis-tp2253205p2279838.html
Sent from the R help mailing list archive at Nabble.com.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to