1
votes

I have data (matrix) with integer values. The colnames is "00","01","02","03" rownames is "01042014","02042014"

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

This is what I did, plot(rownames(data),data[,"Total")), however the plot looks un-understandable. Actually, the rownames(data) is the date and I want to plot it against the Total column.

enter image description here

2

2 Answers

2
votes

You can create a vector of dates:

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"])

Once you have the vec.dates you can append it to the data frame.

G.

0
votes

You can try :

First, sort your data by date:

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".

Then, plot your data:

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)