3

I have used the following code in R to generate this graph:

x  <- c(0.916, 0.815, 0.101, -0.029, -0.166, 0.949, 0.073, -0.054, 1.006)
y  <- c(3.91,  5.17,  1.08,   1.28,   1.01,  4.37,  3.97,   0.77,  4.52)
sd <- c(0.35,  2.26,  0.17,   0.08,   0.27,  0.49,  0.65,   0.12,  1.45)
windows()
plot(x,y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex.axis=0.8, 
     cex.lab=0.9, xlab="Male/Female expression ratio (log)", 
     ylab="Z/W expression ratio in females", las=1)
for (i in 1:9) {
  up  <- y[i] + sd[i]
  low <- y[i] - sd[i]
  segments(x[i],      low, x[i],      up)
  segments(x[i]-0.02, up,  x[i]+0.02, up)
  segments(x[i]-0.02, low, x[i]+0.02, low)
}

My question is that how I can get rid of the two top and right axes and only keep the bottom and left axes?

in the following picture

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Homap
  • 2,142
  • 5
  • 24
  • 34
  • 2
    As a side note, you don't need the `for` loop. `segments` is a vectorised function. You just need to do the 3 lines of: `segments(x,y-sd,x,y+sd);segments(x-epsilon,y+sd,x+epsilon,y+sd);segments(x-epsilon,y-sd,x+epsilon,y-sd);` to get the error bars. This is even said in the answer you got this code from: http://stackoverflow.com/a/15063354/496803 – thelatemail Sep 14 '13 at 11:16

3 Answers3

5

In case you want to keep the box-like appearance instead of "free floating" axes, add bty ="l" (a lower case L) to your plot command.

Resulting in:

plot(x, y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex.axis=0.8, 
     cex.lab=0.9, xlab="Male/Female expression ratio (log)", 
     ylab="Z/W expression ratio in females", las=1, bty = "l")

This will only remove the upper and the right frame bar. See also ?par

Edit:
Looking at your graph and your calculations it seems, that you want to plot means for specific groups and then also show some standard deviation. In this case i would recommend looking into the boxplot() command which will do that for you using your original data. See ?boxplot

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
r0bert
  • 191
  • 3
1

You can also try adding frame = FALSE in your plot command:

plot(x, y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex.axis=0.8, 
     cex.lab=0.9, xlab="Male/Female expression ratio (log)", 
     ylab="Z/W expression ratio in females", las=1, frame = FALSE)
gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Carlos V
  • 101
  • 1
  • 5
0

@r0bert & @CarlosV have provided good answers. There is one other option as well: You can suppress the axes with the argument axes=FALSE and then construct your own using ?axis, which can give you more control over the axes. Here is some example code (as a bonus, I illustrate @thelatemail's comment about the vectorized version of segment()):

plot(x, y, axes=FALSE, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, 
     cex.axis=0.8, cex.lab=0.9, xlab="Male/Female expression ratio (log)", 
     ylab="Z/W expression ratio in females")
axis(side=1, cex.axis=0.8, cex.lab=0.9)
axis(side=2, cex.axis=0.8, cex.lab=0.9, las=1)
segments(x,      y-sd, x,      y+sd)
segments(x-0.02, y+sd, x+0.02, y+sd)
segments(x-0.02, y-sd, x+0.02, y-sd)

enter image description here

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79