1

I used ggplot function to plot the figure, Here is my code for plotting, it combine three different data set.

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

I want to change to color for both line and point. I tried the following 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"))

But the console only shows :

<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>

How do I change the color for this kind of plot?

Below is the data set sample:

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
Delia
  • 15
  • 4
  • 1
    your example is not [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610), could you provide the result of `dput(model_mean_homo)`? – Vincent Bonhomme May 26 '16 at 08:07

1 Answers1

2

Did you mean:

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)
  • I type pp instead of print(pp)。It usually show out the plot when I type pp, but this time doesn't. – Delia May 27 '16 at 02:08
  • Yeah, that is fine, but the problem might be something else: see the difference between: pp <- scale_color_manual() pp <- pp + scale_color_manual() – Marek Bartosovic May 27 '16 at 07:00