简体   繁体   中英

R: change x-axis direction

plot(runif(12)) creates a plot with x-axis numbers: 1, 2, 3, 4 and 5. In this way, the positive direction is left-to-right.

It is possible to define the possitive direction from right to left?.

Something like plot(runif(12), xAxisDirection='right-to-left')

You can reverse the range and pass it to xlim parameter in plot

x <- runif(12)
plot(x, xlim=rev(range(x)))

You could pass the labels and plot the x axis separately:

set.seed(123)
v   = runif(12)
lab = seq(1, length(v), by = 2)
lab = lab[order(-lab)]
lab.at = length(v) - lab + 1

plot(v, xaxt = "n")
axis(1, at = lab.at, labels = lab)

情节 For other data (eg meaningful x labels) you could create an artificial x value that is plotted (eg x.plot = min(x) - x ) to sort the data while you label the x axis with values of your x variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM