使用R中的matplot更改轴标签

时间:2015-03-25 10:54:07

标签: r axis-labels

我正在尝试更改matplot中的x轴,但此命令不起作用:

TimePoints=1997:2011
matplot(t(DataMatrix),type='l',col="black",lwd=1,xlab="Anni",ylab="Rifiuti",main="Produzione rifiuti")
axis(side=1,at=TimePoints,labels=TimePoints)

plot我毫无问题地使用了这个。我该如何解决? 在这里您可以找到对象:https://dl.dropboxusercontent.com/u/47720440/SOF.RData

1 个答案:

答案 0 :(得分:5)

我通常这样做如下:

  1. 完全省略轴。
  2. 逐个添加带有所需选项的轴。
  3. 在R:

    # Add argument axes=F to omit the axes
    matplot(t(DataMatrix),type='l',col="black",lwd=1,xlab="Anni",ylab="Rifiuti",main="Produzione rifiuti",axes=F)
    
    # Add Y-axis as is
    axis(2)
    
    # Add X-axis
    # Note that your X-axis range is not in years but in the "column numbers",
    # i.e. the X-axis range runs from 1 to 15 (the number of columns in your matrix)
    # Possibly that's why your original code example did not work as expected?
    axis(side=1,at=1:ncol(DataMatrix),labels=TimePoints)