[R] plot more plots from one matrix

alcesgabbo alcesgabbo at hotmail.com
Thu Dec 2 16:52:04 CET 2010


Hi,
I have a dataframe like this:

         procedure     property    sensor_data  sensor_date           
                 |             |               |                 |
 [1,] "PAT_Laser_2" "Distance"   "30.42"     "2010-09-30T15:00:12+0200"
 [2,] "PAT_Laser_2" "Distance"   "31.22"     "2010-10-31T15:05:07+0100"
 [3,] "PAT_Laser_2" "Distance"   "30.42"     "2011-09-30T15:00:12+0200"
 [4,] "PAT_Laser_2" "Distance"   "31.22"     "2011-10-31T15:05:07+0100"
 [5,] "PAT_Laser_1" "Distance"   "50.1252"   "2010-09-30T15:00:12+0200"
 [6,] "PAT_Laser_1" "Distance"   "48.532"    "2010-10-31T15:05:07+0100"
 [7,] "PAT_Laser_1" "Distance"   "50.1252"   "2011-09-30T15:00:12+0200"
 [8,] "PAT_Laser_1" "Distance"   "48.532"    "2011-10-31T15:05:07+0100"
 [9,] "PAT_Laser_2" "Distance_B" "3.42"      "2010-09-30T15:00:12+0200"
[10,] "PAT_Laser_2" "Distance_B" "131.22"    "2010-10-31T15:05:07+0100"
[11,] "PAT_Laser_2" "Distance_B" "303.42"    "2011-09-30T15:00:12+0200"
[12,] "PAT_Laser_2" "Distance_B" "131.22"    "2011-10-31T15:05:07+0100"
[13,] "PAT_Laser_1" "Distance_B" "530.1252"  "2010-09-30T15:00:12+0200"
[14,] "PAT_Laser_1" "Distance_B" "428.532"   "2010-10-31T15:05:07+0100"
[15,] "PAT_Laser_1" "Distance_B" "530.1252"  "2011-09-30T15:00:12+0200"
[16,] "PAT_Laser_1" "Distance_B" "148.532"   "2011-10-31T15:05:07+0100"


In order to identify each "sensor_data" with the columns "property" and
"procedure" I create a new column "key" in this way:

    procedure   property sensor_data              sensor_date                   
key
1  PAT_Laser_2   Distance       30.42 2010-09-30T15:00:12+0200  
PAT_Laser_2.Distance
2  PAT_Laser_2   Distance       31.22 2010-10-31T15:05:07+0100  
PAT_Laser_2.Distance
3  PAT_Laser_2   Distance       30.42 2011-09-30T15:00:12+0200  
PAT_Laser_2.Distance
4  PAT_Laser_2   Distance       31.22 2011-10-31T15:05:07+0100  
PAT_Laser_2.Distance
5  PAT_Laser_1   Distance     50.1252 2010-09-30T15:00:12+0200  
PAT_Laser_1.Distance
6  PAT_Laser_1   Distance      48.532 2010-10-31T15:05:07+0100  
PAT_Laser_1.Distance
7  PAT_Laser_1   Distance     50.1252 2011-09-30T15:00:12+0200  
PAT_Laser_1.Distance
8  PAT_Laser_1   Distance      48.532 2011-10-31T15:05:07+0100  
PAT_Laser_1.Distance
9  PAT_Laser_2 Distance_B        3.42 2010-09-30T15:00:12+0200
PAT_Laser_2.Distance_B
10 PAT_Laser_2 Distance_B      131.22 2010-10-31T15:05:07+0100
PAT_Laser_2.Distance_B
11 PAT_Laser_2 Distance_B      303.42 2011-09-30T15:00:12+0200
PAT_Laser_2.Distance_B
12 PAT_Laser_2 Distance_B      131.22 2011-10-31T15:05:07+0100
PAT_Laser_2.Distance_B
13 PAT_Laser_1 Distance_B    530.1252 2010-09-30T15:00:12+0200
PAT_Laser_1.Distance_B
14 PAT_Laser_1 Distance_B     428.532 2010-10-31T15:05:07+0100
PAT_Laser_1.Distance_B
15 PAT_Laser_1 Distance_B    530.1252 2011-09-30T15:00:12+0200
PAT_Laser_1.Distance_B
16 PAT_Laser_1 Distance_B     148.532 2011-10-31T15:05:07+0100
PAT_Laser_1.Distance_B

Now I want to plot the "sensor_data" column for each "sensor_date" so I
create a matrix in this way:


m<-tapply(matrix2plot2[,"sensor_data"],matrix2plot2[,c("sensor_date","key")],c)

                        key
sensor_date                      PAT_Laser_1.Distance PAT_Laser_1.Distance_B
PAT_Laser_2.Distance PAT_Laser_2.Distance_B           
  2010-09-30T15:00:12+0200                    9                     10                   
4                      3
  2010-10-31T15:05:07+0100                    8                      7                   
6                      1
  2011-09-30T15:00:12+0200                    9                     10                   
4                      5
  2011-10-31T15:05:07+0100                    8                      2                   
6                      1

(1° PROBLEM)
And here there is the first problem: instead of having "sensor_data" inside
the matrix there is a sequence of numbers 1,2...,10. (I think it is a way to
simplify the matrix but I would like the original values).

Apart this problem when I do:
matplot(m, type="o", xaxt="n", lty=1)

It is ok, It plots the matrix, each line on the plot represents a column.

(2° PROBLEM)
I would like to have 2 plots, one for the values with "property"= distance
and the other for "property"=distance_B. Is there a way to do this without
use directly the names "distance" and "distance_B" (so it should be possible
to use this method also for other matrix with other "property").


Is it clear?? I don't know if I explained the problem in a clear way.....  

Thanks!

-- 
View this message in context: http://r.789695.n4.nabble.com/plot-more-plots-from-one-matrix-tp3069545p3069545.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list