2016-03-30 7 views
2

Ich habe ein Datenframe, das Zeit und Schlüsselwertpaar enthält, die ich nach Schlüssel gruppieren und dann eine geglättete Linie pro Datengruppe darstellen möchte. Ich möchte es dann mit dem Schlüssel beschriften. Ich kann alles tun, aber die Etiketten basierend auf dem Schlüssel erhalten. Ich kann nicht sehen, wo im Dokument, um dies zu setzen.R - ggvis - Wie kennzeichne ich multiple geglättete Datengruppen

Daten

  Time    newcol  newval 
23/03/2016 21:26 D1_ResponseTime_MS 55.44005444 
23/03/2016 21:27 D1_ResponseTime_MS 37.4510724 
23/03/2016 21:28 D1_ResponseTime_MS 5.286692372 
23/03/2016 21:29 D1_ResponseTime_MS 3.521776483 
23/03/2016 21:26 D2_ResponseTime_MS 2.444971186 
23/03/2016 21:27 D2_ResponseTime_MS 1.632372897 
23/03/2016 21:28 D2_ResponseTime_MS 4.772246899 
23/03/2016 21:29 D2_ResponseTime_MS 3.687779829 
23/03/2016 21:26 D3_ResponseTime_MS 0.752404455 
23/03/2016 21:27 D3_ResponseTime_MS 0.86613441 
23/03/2016 21:28 D3_ResponseTime_MS 0.663330605 
23/03/2016 21:29 D3_ResponseTime_MS 1.020344652 
23/03/2016 21:26 D4_ResponseTime_MS 10.62914139 
23/03/2016 21:27 D4_ResponseTime_MS 24.61302708 
23/03/2016 21:28 D4_ResponseTime_MS 17.00460387 
23/03/2016 21:29 D4_ResponseTime_MS 5.785255247 
23/03/2016 21:26 S1_ResponseTime_MS 12.82984893 
23/03/2016 21:27 S1_ResponseTime_MS 6.452076474 
23/03/2016 21:28 S1_ResponseTime_MS 1.763004864 
23/03/2016 21:29 S1_ResponseTime_MS 2.374506918 
23/03/2016 21:26 S2_ResponseTime_MS 2.034700375 
23/03/2016 21:27 S2_ResponseTime_MS 8.002695351 
23/03/2016 21:28 S2_ResponseTime_MS 25.60619709 
23/03/2016 21:29 S2_ResponseTime_MS 1.386355077 
23/03/2016 21:26 S4_ResponseTime_MS 3.443398856 
23/03/2016 21:27 S4_ResponseTime_MS 3.67701968 
23/03/2016 21:28 S4_ResponseTime_MS 7.901357583 
23/03/2016 21:29 S4_ResponseTime_MS 6.685758779 
23/03/2016 21:26 S5_ResponseTime_MS 1.007202665 
23/03/2016 21:27 S5_ResponseTime_MS 1.245214566 
23/03/2016 21:28 S5_ResponseTime_MS 1.167656668 
23/03/2016 21:29 S5_ResponseTime_MS 0.585119525 
23/03/2016 21:26 S6_ResponseTime_MS 1.913596402 
23/03/2016 21:27 S6_ResponseTime_MS 2.576953267 
23/03/2016 21:28 S6_ResponseTime_MS 1.908091138 
23/03/2016 21:29 S6_ResponseTime_MS 3.872218635 

Ergebnis

enter image description here

-Code

test5 %>% 
ggvis(~Time, ~newval) %>% 
group_by(newcol) %>% 
layer_smooths() %>% 
add_axis("x", properties = axis_props(
    axis = list(stroke = "black", strokeWidth = 2), 
    grid = list(stroke = "black"), 
    ticks = list(stroke = "black", strokeWidth = 2), 
    labels = list(angle = 45, align = "left", fontSize = 10) 
)) 
+0

Bitte posten Sie Ihre Beispieldaten, können wir nicht mit Screenshots alles tun. – mtoto

+0

aktualisiert mit Daten –

+0

Sie können an der Ausgabe von dput() erhalten Sie hier [link] (https://onedrive.live.com/redir?resid=9DC28E4A63FAF571!5465&authkey=!ACXQVt-6MoXPUL8 & thintaint=file%2cout) –

Antwort

0

Sie könnten versuchen, einen stroke Parameter layer_smooths Hinzufügen die sie durch Ihre Gruppierung Farbe und wird auch hinzufügen eine Legende:

df %>% ggvis(~time, ~newval) %>% 
    group_by(newcol) %>% 
    layer_smooths(stroke=~newcol) %>% 
    add_axis("x", properties = axis_props(
     axis = list(stroke = "black", strokeWidth = 2), 
     grid = list(stroke = "black"), 
     ticks = list(stroke = "black", strokeWidth = 2), 
     labels = list(angle = 45, align = "left", fontSize = 10) 
    )) 

produziert:

enter image description here

Wenn Sie jede der Zeilen markiert tun möchten, können Sie einen kleinen Datenrahmen mit den Beschriftungen erstellen und dass als zusätzliche layer_text machen.

label_df <- df %>% group_by(newcol) %>% sample_n(1) 

df %>% ggvis(~time, ~newval) %>% 
    group_by(newcol) %>% 
    layer_smooths(stroke=~newcol) %>% 
    layer_text(data=label_df, 
       text:=~newcol, 
       baseline:="middle", fontSize:=8) %>% 
    add_axis("x", properties = axis_props(
     axis = list(stroke = "black", strokeWidth = 2), 
     grid = list(stroke = "black"), 
     ticks = list(stroke = "black", strokeWidth = 2), 
     labels = list(angle = 45, align = "left", fontSize = 10) 
    )) 

enter image description here