在 r 中更改 X 轴值

Changing X-Axis Values in r

我想在 R 中更改绘图的 x 轴。这是我的示例:

plot(cbind(result, result),xlim=c(max(result),min(result)),
     ylim=c(min(result),max(result)), xaxt="n")
axis(1, at=result)

result
## [1] 0.6256767 0.6833695 0.7671350 0.5205373 0.4932262 0.5852338 0.5088692 0.3379572
## [9] 0.3420370 0.3029084 0.4677624 0.4822537 0.3047485 0.3852572 0.3186014 0.2009436
## [17] 0.1882227 0.2090007 0.2654110 0.3334744

我想在 x 轴上设置从 1 到 20 的新值。我尝试使用 axis(1, at=seq(1, 20)),但没有成功。我该怎么办?

这是一个对您的示例进行了最少更改的解决方案。基本上,我用观测值创建了一个 data.frame。由于该图将所有观察结果按降序排列,因此我也对新创建的 data.frame 执行此操作。这就是我在 axis 调用中使用的内容。

result <-c(0.6256767,0.6833695,0.7671350,0.5205373,0.4932262,0.5852338,0.5088692,0.3379572,
  0.3420370,0.3029084,0.4677624,0.4822537,0.3047485,0.3852572,0.3186014,0.2009436,
  0.1882227,0.2090007,0.2654110,0.3334744)

result_df <-data.frame(my_order=1:length(result),result=result) #add column with initial observation number
result_df <-result_df[order(result_df$result, decreasing = TRUE),] #decreasing order

plot(cbind(result, result),xlim=c(max(result),min(result)),
     ylim=c(min(result),max(result)), xaxt="n")
axis(1, at=result_df$result,labels=result_df$my_order,cex.axis=0.6)