Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to plot different class of time series data into one panel?
    primarykey
    data
    text
    <p>I have several product's hourly summary of multiple attributes in one table.</p> <p>and I would like to plot them into one panel where x-axis stands for time and different type of products have different color.</p> <p>My data looks like this:</p> <pre><code>&gt; require(data.table) # Create some data &gt; dt&lt;-data.table(type=c(rep("a",168),rep("b",168),rep("c",168)), time=1:168,A=rnorm(168,10,5),B=rnorm(168,100,20),C=rnorm(168,10,5)) &gt; DT #Each type has 1~168 hours summary of all three attributes type time A B C 1: a 1 7.462817 119.91299 7.404987 2: a 2 7.733695 146.14601 -3.203601 3: a 3 19.034468 84.45497 9.623048 4: a 4 8.813990 123.21235 12.719920 5: a 5 16.803735 92.69359 11.393730 --- 500: c 164 18.016771 90.29856 10.238281 501: c 165 6.566802 131.67801 -2.085370 502: c 166 20.031678 83.34749 12.261008 503: c 167 4.705976 109.76303 9.327958 504: c 168 8.648876 84.67477 19.036321 </code></pre> <p>By applying <code>plot.zoo</code> i can plot one type a time like this:</p> <pre><code>&gt; setkey(DT,type) &gt; plot(zoo(DT["a"])[,3:5]) </code></pre> <p>But how can i plot all the products into one panel where different colors represents different types?</p> <p><strong>EDITED:</strong> I think my original questions can be interpreted into 2 meanings: How to put "A","B","C" (different columns) into one panel and How to put "a" "b" "c" (different type value in rows) into one panel. Both @Joshua Ulrich and @Paul Hiemstra have answered the first question but what i really want to know is the second one. For better understanding i rename the colnames of DT</p> <pre><code>&gt; names(DT)&lt;-c("type","time","Attr1" ,"Attr2" , "Attr3" ) &gt; DT type time Attr1 Attr2 Attr3 1: a 1 7.462817 119.91299 7.404987 2: a 2 7.733695 146.14601 -3.203601 3: a 3 19.034468 84.45497 9.623048 4: a 4 8.813990 123.21235 12.719920 5: a 5 16.803735 92.69359 11.393730 --- 500: c 164 18.016771 90.29856 10.238281 501: c 165 6.566802 131.67801 -2.085370 502: c 166 20.031678 83.34749 12.261008 503: c 167 4.705976 109.76303 9.327958 504: c 168 8.648876 84.67477 19.036321 </code></pre> <p>What i am looking for is a plot with 3 panels, each panel represent an ATTRIBUTE ("Attr1", "Attr2", "Attr3"), within each panel, there are several lines(time series) with different colors represent different types of data ("a","b","c") </p> <p>Sorry for the previous misleading</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload