# [R] changing coordinates?

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Oct 29 12:46:49 CET 2002

```Hi Richard

It doesn't matter whether you use rows for the x or the y axis.  The
plot commands take sets of data points.  Pass plot two vectors for x and
y and you get your plot.  So if, for example, depth is your "x-axis",
but you want it where the "y-axis" is and you want to plot some data
against it (oxygen profile) then:

plot(x = o2, y = depth) #where o2 and depth are rows or columns of a
data frame, matrix, or two vectors.

Now, I'm a (palaeo)limnologist and we often want y-axis to start from 0
at the top left like you do.  The beauty of R (over some of the other
stratigraphic plotting tools I have had the misfortune to use over the
years) is that you can very simply tell plot() what the axis should be
ranged like:

o2 <- c(1, 5, 6, 8, 10, 2, 3, 4, 8, 9, 15, 10, 4, 7, 3) # made-up o2
profile (random typing ;-) )
depth <- c(0:14) # depth in m from 0m to 14m

plot(x = o2, y = depth, ylim = c(14, 0) + 0.1, type="b", main="O2
profile for Foo Lake")

If you want to pop the "x-axis" (o2) labels along the top rather than
the default (bottom) then something like this will work:

oldpar <- par(mar = c(3, 4, 5, 2) + 0.1) # give a larger top and smaller
bottom margins
plot(x = o2, y = depth, ylim = c(14, 0) + 0.1, type="b", main="O2
profile for Foo Lake",
axes = FALSE) #don't plot the axes
axis(side = 2)	# plot the left axis
axis(side = 3)	# plot the top axis
box()			# finish off with a box round the plot
par(oldpar)		# reset margins

So as you can see R's graphics are very flexible and can be made to do
what you want (mostly!).  And that's without getting into lattice()
graphics.

I suggest that you have a look at the Introduction to R manual from CRAN
(under documentation) and read the plotting section for an overview of
what is possible.  Or see one of the Contributed texts (e.g.
Maindonald's "Using R for Data Analysis and Graphics").

Almost every graphics or plotting requirement I have had to do with my
PhD data I have been able to do it in R.  The only thing I couldn't do
was plot vertical dendrograms to finish off an image() plot with
separate dendrograms along the top and the left of the plotting area,
but this has now been added to the functionality of R (from 1.6.0).

Gav

%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpson at ucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

-----Original Message-----
From: owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch] On Behalf Of Richard Mueller
Sent: 28 October 2002 21:25
To: r-help at stat.math.ethz.ch
Subject: [R] changing coordinates?

I just detected R and have, after browsing the manual, one question:
I look for quite a lot of time for graphical software which allows to
plot data from a table or external file _with the axes of the coordinate

system changed_, i.e. the x-axis should run from top left to bottom
left, and the y-axis from top-left to top-right. It is of no use to
interchange the rows in the table, the coordinate system should rely of
that definition. This type of plot is used in limnological and
oceanological graphs. Until now I could find no software which can do
that job. Perhaps one of you can answer this beginner's question with a
simple yes or no?
Thank you, Richard

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```