1

I am attempting to create a figure with a break in the axis.

It creates the .jpg image, but it prints two sets of x-axis labels in the process (see attached picture).

What error in the code is resulting in this problem?

results = read.table("./ceu_asn_afr.txt",head=T)
library(plotrix)
jpeg("Figure1.1.jpg",width=2000,height=2000,res=300)
xgap <- ifelse(as.numeric(results[,1]) > 1.9, as.numeric(results[,1])-0.4, as.numeric(results[,1]))
plotCI(xgap,as.numeric(results[,3]),ui=as.numeric(results[,5]),li=as.numeric(results[,4]),err="y",gap=TRUE,sfrac=0.005, xlab="European odds ratio",ylab="African American odds ratio",cex=1.5,bty="l")
xat <- pretty(xgap)
xat <- xat[xat!=1.6]
xlab <- ifelse(xat>1.5, xat+0.4, xat)
axis(1,at=xat, labels=xlab)
axis.break(1,1.9,style="slash")
lines(c(0.75,2.5),c(0.75,2.5),lty=2)
close.screen(all=TRUE)
dev.off()

Output from code as it stands

Vincent Laufer
  • 705
  • 10
  • 26
  • Suspect it's caused by your combined use of `axis` and `axis.break`. The `gap.plot( , , gap.axis="x", ...)` function in plotrix is designed to bundle these various dependnecies. The break location in your current code does not match the labels you constructed. And you should be using `xaxt="n"` to suppress the default x-axis in `plotCI`. – IRTFM Jan 12 '15 at 20:45
  • perhaps, although elsewhere this seems to be the approach used. Axis.break merely puts the lines in, if I understand correctly. Refer to this example, for instance: http://stackoverflow.com/questions/19612348/break-x-axis-in-r – Vincent Laufer Jan 12 '15 at 20:49
  • "perhaps"? Perhaps what? I made three separate points. I didn't do any coding because your example is not reproducible. If you can replace the code with the details of the prior question and ask a new question then please do so. (It was reproducible.) – IRTFM Jan 12 '15 at 20:51

1 Answers1

0

based on feedback from https://stackoverflow.com/users/1855677/bondeddust, the code should be emended to read (see double asterisks):

results = read.table("./ceu_asn_afr.txt",head=T)
library(plotrix)
jpeg("Figure1.1.jpg",width=2000,height=2000,res=300)
xgap <- ifelse(as.numeric(results[,1]) > 1.9, as.numeric(results[,1])-0.4, as.numeric(results[,1]))
plotCI(xgap,as.numeric(results[,3]),ui=as.numeric(results[,5]),li=as.numeric(results[,4]),err="y",gap=TRUE,sfrac=0.005, xlab="European odds ratio",ylab="African American odds ratio",cex=1.5,bty="l",**xaxt="n"**)
xat <- pretty(xgap)
xat <- xat[xat!=1.6]
xlab <- ifelse(xat>1.5, xat+0.4, xat)
axis(1,at=xat, labels=xlab)
axis.break(1,1.9,style="slash")
lines(c(0.75,2.5),c(0.75,2.5),lty=2)
close.screen(all=TRUE)
dev.off()

because plotCI defaults to creation of axis labels.

Community
  • 1
  • 1
Vincent Laufer
  • 705
  • 10
  • 26