2015-04-14 2 views
1

Это можно сделать очень легко.Участок два xaxis в одном сюжете?

xvals <- c(5.5, 15.5, 25.5, 35.5, 45.5, 55.5, 65.5, 75.5, 85.5, 95.5) 
yvals <- c(81, 63, 45, 27, 9, -9, -27, -45, -63, -81) 
xn <- rep(1000, 10) 
plot(xvals, yvals) 

Оба xvals и доля хпа тот же yvals, так что я хочу построить на одном графике:

yaxis: 
    xaxis lower:xvals 
    xaxis upper:xn 

enter image description here

Я просто хочу, чтобы добавить xn на тот же участок, как Xaxis (верхняя) ось (3). Любая идея!

ответ

2

Оставьте свой код как будто plot(xvals, yvals). Затем добавьте следующее:

#plot the first plot 
plot(xvals, yvals) 
#start new overlaid plot 
par(new=TRUE) 
#plot xn but remove the xaxis and the x label for now 
plot(xn, yvals, xaxt='n', xlab='') 
#add those at the top of the graph (3) 
axis(3, xn) 
#bonus. add this line to add a secondary xlabel on top 
mtext(side = 3, line = 2, "xn") 

Результат:

enter image description here

Смежные вопросы