[R] how to plot y-axis on the right of x-axis

Jim Lemon jim at bitwrit.com.au
Wed Aug 25 11:39:33 CEST 2010


On 08/25/2010 09:12 AM, elaine kuo wrote:
> Dear List,
>
> I have a richness data distributing across 20 N to 20 S latitude. (120 E-140
> E longitude).
>
>
> I would like to draw the richness in the north hemisphere and a regression
> line in the plot
> (x-axis: latitude, y-axis: richness in the north hemisphere).
> The above demand is done using plot.
>
> Then, south hemisphere richness and regression are required to be generated
> using
> the same y-axis above but an x-axis on the left side of the y-axis.
> (The higher latitude in the south hemisphere, the left it would move)
>
> Please kindly share how to design the south plot and regression line for
> richness.
> Also, please advise if any more info is in need.
>
Hi Elaine,
Changing the position of the axes is easily done by changing the "side" 
and "pos" arguments of the "axis" function. If you want to move the 
y-axis to the right (or as you state it, the x axis to the left):

# y axis on the left
plot(1:5,axes=FALSE)
axis(1)
axis(2)
# add a y axis one third of the way to the right
xylim<-par("usr")
axis(2,pos=xylim[1]+diff(xylim[1:2])/3)
# add another y axis two thirds of the way
axis(4,pos=xylim[2]-diff(xylim[1:2])/3)
# add one more on the right
axis(4)

You can move the x axis up and down using the same tricks.

Jim



More information about the R-help mailing list