R matplot()函数:如何保持索引在x轴上,但只从矩阵中绘制特定值



假设你有一个向量

a = c(1:10)

但是我只想画出元素2,5和7,但是在下标2,5,7处。非:y值为2,5和7,x值为1,2,3

我可以使用:

plot(a[c(2,5,7)],a[c(2,5,7)])
plot_subset_ind

然而,对于函数matplot(),在绘制矩阵时,我不知道如何做到这一点:

原始:

matplot(t(max_invest_year_zero_matrix/1000))

不工作,因为所有数据都移动了一个索引:

matplot(t(max_invest_year_zero_matrix[,plot_subset_ind]/1000))

也许我应该用NaN值代替未绘制的值。

不清楚是要绘制一些列还是所有列中的一些行。
请看下面两幅图的区别。请注意,两者都没有使用t()

max_invest_year_zero_matrix <- matrix(1:64, ncol = 8)
plot_subset_ind <- c(2, 5, 7)
matplot(max_invest_year_zero_matrix[plot_subset_ind, ])
matplot(max_invest_year_zero_matrix[, plot_subset_ind])

最新更新