[R] plot the y-axis upside down

Marc Schwartz marc_schwartz at me.com
Fri Jun 17 21:47:16 CEST 2011


On Jun 17, 2011, at 2:31 PM, Owen, Jason wrote:

> Hello,
> 
> I need to create a scatterplot where the y-axis is upside down.  If I have non-negative bivariate data in objects "x" and "y," then the operation
> 
> plot(x, -y)
> 
> gives me the figure I want -- a mirror image of plot(x, y) -- except that the y-values (coordinates) are negative, which I don't want.  Is there a simple way to do this?
> 
> Jason


This is where the 'ylim' argument to plot is helpful, along with ?rev and ?range:

  x <- 1:10
  y <- 1:10
  plot(x, y)

versus:
  
  plot(x, y, ylim = rev(range(y)))

HTH,

Marc Schwartz



More information about the R-help mailing list