1

I am trying to get rid of the X and Y axes lines in R but it seems impossible. I am running the below code:

par(mar=c(5,5,5,5), cex.main = 1.5, col.main = "gray30", bg="white", cex = 
0.8, family="Calibri", las=1)
plot(y1~x, col=blk_blue, type="l", lwd=2, ylim = y1_limits, xlab = x_label, 
ylab = y1_label, las=1, axes=FALSE)

rect(par("usr")[1], par("usr")[3], par("usr")[2], par("usr")[4], col = 
"gray90", border=NA)
grid(nx = 5, ny = 5, col = "white", lty = "solid", lwd = 1)
grid(nx = 10, ny = 10, col = "white", lty = "dotted", lwd = 1)

par(new=TRUE, las=1, bty="n")
plot(y1~x, col=blk_blue, type="l", lwd=2, ylim = y1_limits, xlab = x_label, 
ylab = y1_label)

axis(side=1, col = "white", labels = FALSE)
axis(side=2, col = "grey90", labels = FALSE, ylim = y1_limits)
axis(side=3, col = "grey90", labels = FALSE, tick = FALSE)
mtext(y2_label, side=4, line=3)

par(new=TRUE, bty="n", las=1, bty="n")
plot(y2~x, col=blk_red, type="l", lwd = 2, axes=FALSE, xlab = "", ylab="", 
ylim=y2_limits, las=1, xaxt="n")
axis(side = 4,  ylim = y2_limits, col="grey90")

and the resulting chart looks like the below: enter image description here

As you can see there are still some remainder black segments in the x-axis. How can I remove those?

stratar
  • 119
  • 7
  • Try adding `bty = "n"` to each plot statement. Otherwise please provide a [reproducible example](https://stackoverflow.com/a/5963610/4421870) – Mako212 Sep 12 '17 at 17:49
  • The code gives errors, first there's no object named `blk_blue`, then it's `object 'y1_limits' not found`. And there are other missing objects. Can you please post their values? – Rui Barradas Sep 12 '17 at 17:49
  • thanks Rui. blk_blue is just a colour, You can replace it with "blue" let's say. Same for blk_red. y1_limits <- c(-3,9), y2_limits <- c(-150,200). – stratar Sep 12 '17 at 17:51
  • thanks Mako. Adding bty="n" does not resolve the issue. I tried this before and once again to verify. – stratar Sep 12 '17 at 17:53

1 Answers1

0

In your calls to plot(...), set axes=FALSE

In your calls to axis(...), set labels=TRUE

I believe this solves the issue, it prevents the black axis lines from being plotted in the first place but it still plots the numbers along the axes.

Dustin
  • 61
  • 2
  • thank Justin. This creates another issue, which is that it converts my x-axis dates into large integers, i.e. 14,000 , 16,000 etc. – stratar Sep 12 '17 at 19:11
  • my comment above can be resolved with the use of axis.Date(). Other than that your solution works so I will mark your answer as correct. – stratar Sep 12 '17 at 22:02