[R] : plot different axis, same plot position

Pelt van, Saskia (KNMI) saskia.van.pelt at knmi.nl
Wed Nov 17 18:19:42 CET 2010


Dear R-users,
 
I am trying to make a plot in R where x and y are plotted in a regular way, but the x axis corresponds to another set of values. 
 
For example I have x,y and T (all 29 values) 
 
x<- c( -1.31846232, -1.04744756, -0.87034853, -0.72883370, -0.60618971, -0.49501845, -0.39128988, -0.29250120, -0.19694055, -0.10334039, -0.01069355,  0.08185470,  0.17507665,  0.26971270,  0.36651292,
0.46627625,  0.56989300,  0.67839644,  0.79303127,  0.91535108, 1.04736522,  1.19177282,  1.35235778,  1.53470330,  1.74760041, 2.00616370,  2.33996397,  2.82073311,  3.72564504)
 
y<-c(51.85177,  53.67026,  60.64062,  62.33320,  62.81224,  63.20116,76.10719,  78.07620,  78.83859,  80.06188,  84.53568,  85.15358, 87.39279,  87.49965,  89.88347,  90.73792,  90.92971,  92.17759,
92.84064,  93.17964,  97.51360,  97.64690,  98.20756, 101.64150,104.91425, 112.88917, 116.90400, 121.50099, 126.43808)
 
T<- c(1.190283,  1.240506, 1.295154,  1.354839,  1.420290,  1.492386,  1.572193,  1.661017,
1.760479,  1.872611,  2.000000,  2.145985,  2.314961,  2.512821, 2.747664,  3.030928,  3.379310,  3.818182,  4.388060,  5.157895,  6.255319,  7.945946, 10.888889, 17.294118, 42.000000)
 
plot(x,y,xlab="x", ylab="10 day maximum (mm)",col="blue",type="b",pch=1,lty=2) 
 
This plot is the correct plot, but I want the x-axis to display the values of T 
If I do this:
 
plot(x,y,xlab="x", ylab="10 day maximum (mm)",xaxt="n", col="blue",type="b",pch=1,lty=2) 
axis(1,las=0,T)
 
than the T is plotted in stead of x, but on the same scale. So the tickmarks start at 1 and stop at 3. I would like each point of the graph to correspond to a value of T on the x-axis, but the plot position should still correspond to x. 
This means that y corresponds to the x values in plot position, but to the T value on the x-axis. I want this because the x values have no explanatory meaning (Gumbel variates), while the T values (return period)  have, so I can use it to communicate what is happening in this graph. 
 
I hope somebody can help me with this. 
 
Kind regards,
 
Saskia van Pelt
 
 

 

 



More information about the R-help mailing list