2016-05-26 4 views
0

Ich verwendete ggplot Funktion, um die Figur zu plotten, Hier ist mein Code zum Plotten, es kombiniert drei verschiedene Datensätze.Definieren Sie die Farbe manuell auf Punkt und Linie in ggplot (R)

pp<-ggplot(model_mean_homo,aes(x=m_tau,y=track_err,colour=model,group=model))+geom_line(size=2) 
pp<-pp+geom_line(data=model_topN,aes(x=model_topN$m_tau,y=model_topN$track_err,colour=top_N,group=top_N)) 
pp<-pp+geom_point(data=model_mem,aes(x=model_mem$m_tau,y=model_mem$track_err,colour=model)) 

enter image description here

Ich möchte sowohl für Linie und Punkt Farbe ändern. Ich habe versucht, den folgenden Code:

pp<-scale_color_manual(values = c("ECMWF"="red","NCEP"="blue","ECMWF+NCEP"="green","5"="red1","10"="orange","15"="yello3","20"="green3","15"="black"),limits = c("ECMWF","NCEP","ECMWF+NCEP","5","10","15","20")) 

Aber die Konsole zeigt nur:

<ggproto object: Class ScaleDiscrete, Scale> 
    aesthetics: colour 
    break_info: function 
    break_positions: function 
    breaks: waiver 
    call: call 
    clone: function 
    dimension: function 
    drop: TRUE 
    expand: waiver 
    get_breaks: function 
    get_breaks_minor: function 
    get_labels: function 
    get_limits: function 
    guide: legend 
    is_discrete: function 
    is_empty: function 
    labels: waiver 
    limits: ECMWF NCEP ECMWF+NCEP 5 10 15 20 
    map: function 
    map_df: function 
    na.value: NA 
    name: waiver 
    palette: function 
    range: <ggproto object: Class RangeDiscrete, Range> 
     range: NULL 
     reset: function 
     train: function 
     super: <ggproto object: Class RangeDiscrete, Range> 
    reset: function 
    scale_name: manual 
    train: function 
    train_df: function 
    transform: function 
    transform_df: function 
    super: <ggproto object: Class ScaleDiscrete, Scale> 

Wie ändere ich die Farbe für diese Art von Handlung?

Unten ist der Datensatz Beispiel:

head(model_mean_homo) 
    YY  model filetype m_tau track_err datano 
1 2015 ECMWF+NCEP ensemble  0 35.44013 307 
2 2015 ECMWF+NCEP ensemble  6 36.92316 300 
3 2015 ECMWF+NCEP ensemble 12 43.44246 297 
4 2015 ECMWF+NCEP ensemble 18 48.68222 284 
5 2015 ECMWF+NCEP ensemble 24 57.60609 280 
6 2015 ECMWF+NCEP ensemble 30 64.35638 268 

head(model_topN) 
    YY model filetype m_tau track_err datano top_N 
1 2015 NCEP ensemble  0 26.67671 618  5 
2 2015 NCEP ensemble  6 27.97913 609  5 
3 2015 NCEP ensemble 12 31.18090 594  5 
4 2015 NCEP ensemble 18 34.23283 575  5 
5 2015 NCEP ensemble 24 37.31816 557  5 
6 2015 NCEP ensemble 30 43.25841 541  5 

head(model_mem) 
    YY model filetype m_member m_tau track_err datano 
1 2015 ECMWF ensemble  0  0 44.96796 397 
2 2015 ECMWF ensemble  0  6 47.30694 390 
3 2015 ECMWF ensemble  0 12 55.97534 383 
4 2015 ECMWF ensemble  0 18 61.36752 367 
5 2015 ECMWF ensemble  0 24 69.96123 363 
6 2015 ECMWF ensemble  0 30 79.56475 345 
+1

Ihr Beispiel ist nicht [reproduzierbar] (http://stackoverflow.com/questions/5963269/how- make-a-great-r-reproduzierbar-Beispiel/5963610 # 5963610), könnten Sie das Ergebnis von 'dput (model_mean_homo)' bereitstellen? –

Antwort

0

Meinten Sie:

pp <- pp + scale_color_manual(values = c("ECMWF"="red","NCEP"="blue","ECMWF+NCEP"="green","5"="red1","10"="orange","15"="yello3","20"="green3","15"="black"),limits = c("ECMWF","NCEP","ECMWF+NCEP","5","10","15","20")) 
print(pp) 
+0

Ich tippe pp anstelle des Druckes (pp.). Es zeigt normalerweise die Handlung an, wenn ich pp. Schreibe, aber dieses Mal nicht. – Delia

+0

Ja, das ist in Ordnung, aber das Problem könnte etwas anderes sein: sehen Sie den Unterschied zwischen: pp <- scale_color_manual() pp <- pp + scale_color_manual() –

+0

Vielen Dank. Es klappt. – Delia

Verwandte Themen