0

I'm trying to make a graph using the package plotrix in R and I'm having trouble getting it to display the way I would like. Due to how the data is interpreted, positive numbers actually mean that the individuals in that group performed worse and negative numbers mean they performed better. This is confusing when the y-axis is plotted normally (increasing numbers as you go up), but might be easier to interpret if the y-axis was flipped.

I was able to flip the y-axis values and the points plot correctly, but I lose my error bars in the process and I'm not sure why. Here is some example code that demonstrates the issue:

Plot with "normal" y-axis (increasing numbers as you go up):

#rm(list=ls(all=TRUE))  
library(plotrix)  
longxlim <- c(0,4)  
longylim <- c(-2,2)  
plotCI(x = c(1:3), 
   y = c(-1:1), 
   uiw = c(0.25, 0.5, 0.75),
   xlim = longxlim, ylim = longylim,
   pch = c(1:3))

Plot with "flipped" y-axis (decreasing numbers as you go up):

longxlim <- c(0,4)
longylim <- c(2,-2)
plotCI(x = c(1:3), 
   y = c(-1:1), 
   uiw = c(0.25, 0.5, 0.75),
   xlim = longxlim, ylim = longylim,
   pch = c(1:3))
IRTFM
  • 258,963
  • 21
  • 364
  • 487
N. Anderson
  • 17
  • 1
  • 4

1 Answers1

1

instead of negating the limits, maybe negate the y-values themselves?

library(plotrix)  
longxlim <- c(0,4)  
longylim <- c(-2,2)  
yplot <- c(-1:1)


plotCI(x = c(1:3), 
       y = -yplot, 
       uiw = c(0.25, 0.5, 0.75),
       xlim = longxlim, ylim = longylim,
       pch = c(1:3))

To change the y-axis labels you can set yaxt = 'n' and use axis

longxlim <- c(0,4)  
longylim <- c(-2,2)  
yplot <- c(-1:1)
ylabs <- c(-2:2)

plotCI(x = c(1:3), 
       y = -yplot, 
       uiw = c(0.25, 0.5, 0.75),
       xlim = longxlim, ylim = longylim,
       pch = c(1:3), yaxt = 'n')
axis(2, at = ylabs, labels = -ylabs)

enter image description here

jrlewi
  • 486
  • 3
  • 8
  • This will work for my purposes. If someone else has a way to accomplish what the original question was hoping for, please feel free to provide an answer. For now, I will mark @lewisjr2 's answer as correct. – N. Anderson Jan 08 '18 at 19:25
  • I'm guessing you are talking about the labels on the y-axis? See my edit. Hope this helps. – jrlewi Jan 09 '18 at 01:55
  • Yes, that's is what I was talking about. Thank you @lewisjr2. – N. Anderson Jan 09 '18 at 18:14