# [R] Odp: Plot a matrix

Petr PIKAL petr.pikal at precheza.cz
Tue Nov 30 13:41:06 CET 2010

```Hi

r-help-bounces at r-project.org napsal dne 30.11.2010 11:52:38:

>
> I explain better....
>
>                   key
> index               sensor1.A sensor1.B sensor2.A sensor2.B sensor3.A
>   2010-10-1 7:32:00         8        NA         5        NA         2
>   2010-10-3 4:33:21        NA         3        NA         2         1
>   2010-10-5 7:32:00        NA         4        NA         6         7
>
> its a matrix.

Maybe.
>
>
> The first row contains a list (not exactly an array) of date (index it's
> just a name, I can substitute that nale with "Dates" for example)
>
> if I do:
> str(m[,0])
>
>  int[1:3, 0 ]
>  - attr(*, "dimnames")=List of 2
>   ..\$ index: chr [1:3] "2010-10-1 7:32:00" "2010-10-3 4:33:21"
"2010-10-5
> 7:32:00"
>   ..\$ key  : NULL

What you see here are only row names. You can check it by

dimnames(m)

>
>
> If I do:
>
> plot(m[,5],type="o")
>
> I can see 3 point with lines:
> sensor3.A
> 2
> 1
> 7
>  it is OK
> but in the x axes there is
> 1.0 1.5 2.0 2.5 3.0
> instead of
> 2010-10-1 7:32:00   2010-10-3 4:33:21   2010-10-5 7:32:00

Why do you expect to get the above values as axis labels? You did not give
it to plot command? You can modify it by calling plot with axes=FALSE and
put labels from row names by axis command.

plot(m[,5],type="o", axes=FALSE)
axis(1, at=1:3,labels=row.names(m))

Regards
Petr

>
> How can I solve this problem??
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Plot-a-matrix-
> tp3065094p3065163.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

```

More information about the R-help mailing list