r - Plot two xaxis in one plot? -
this can plotted easily.
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)
both xvals , xn share same yvals want plot in 1 graph:
yaxis: xaxis lower:xvals xaxis upper:xn
i want add xn
same plot xaxis (the upper) axis(3). idea on this!
leave code plot(xvals, yvals)
. add following:
#plot first plot plot(xvals, yvals) #start new overlaid plot par(new=true) #plot xn remove xaxis , x label plot(xn, yvals, xaxt='n', xlab='') #add @ top of graph (3) axis(3, xn) #bonus. add line add secondary xlabel on top mtext(side = 3, line = 2, "xn")
result:
Comments
Post a Comment