在ggplot(R)中的点和线上手动定义颜色

时间:2016-05-26 08:00:16

标签: r ggplot2

我用ggplot函数绘制图形, 这是我的绘图代码,它结合了三种不同的数据集。

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

我想换行和点的颜色。 我尝试了以下代码:

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

但控制台只显示:

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

如何更改此类情节的颜色?

以下是数据集样本:

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 个答案:

答案 0 :(得分:1)

你的意思是:

Auth::attempt