[R] Break in the y-axis
Jim Lemon
jim at bitwrit.com.au
Sun Jun 13 13:49:48 CEST 2010
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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: axis.break.R
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100613/9d3b71b8/attachment.pl>
More information about the R-help
mailing list