R中的矩阵数据

时间:2014-12-01 13:18:42

标签: r

我有带整数值的数据(矩阵)。 这些姓氏是" 00"," 01"," 02"," 03" rownames是" 01042014"," 02042014"

                          00       01       02    Total
           01042014 53114424 28401012 16445913 14235413
           02042014 53114424 28401012 16445913 14235413

这就是我所做的,绘图(rownames(数据),数据[," Total")),但情节看起来不可理解。 实际上,rownames(数据)是日期,我想根据Total列绘制它。

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以创建日期向量:

vec.dates<-rownames(data_mat)
vec.dates<-as.Date(as.character(vec.dates), "%d%m%Y") # This is assuming your dates 
                    ## are dd-mm-YYYY. if mm-dd-YYYY, change the last part to "%m%d%Y"

# Then plot against this new vector
plot(vec.dates,data[,"Total"])

获得vec.dates后,您可以将其附加到数据框。

-G。

答案 1 :(得分:0)

您可以尝试:

首先,按日期对数据进行排序:

data_mat<-data_mat[order(strptime(rownames(data_mat),format="%d%m%Y")),]
# this code supposes that your dates are with day first, then month and year. In case the 2 first figures are for the month, replace "%d%m%Y" by "%m%d%Y".

然后,绘制数据:

plot(1:nrow(data_mat),data_mat$Total,axes=F,xlab="Date",ylab="Total",xlim=c(0,nrow(data_mat)+1))
box()
axis(1,at=1:nrow(data_mat),labels=rownames(data_mat))
axis(2,las=1)