根据ggplot2中的分组,着色点,平滑线和置信区间

时间:2016-10-31 18:47:14

标签: r ggplot2 colors smooth

我使用ggplot2创建了一个图表,该图表根据我的组(即gnc和mr)着色。但是,我无法更改所有元素的默认颜色(点,平滑线,置信区间+它们在图例中的显示方式),这与我的分组有关(即,与gnc相关的所有元素的一种独特颜色和另一种独特颜色与mr相关的所有元素。什么是最好的前进方式?任何帮助非常感谢!

数据集:

    lat<-c(37.30,37.30,37.30,37.30,69.25,69.25,37.30,0.00,0.00,37.30,37.30,37.30,37.30,-75.00,-75.00,70.00,25.30,25.30,37.30,45.00,46.75,-49.00,-49.00,-49.00,58.50,-37.00,37.30,37.30,37.30,37.30,69.25,69.25,37.30,0.00,0.00,37.30,37.30,37.30,37.30,-75.00,-75.00,70.00,25.30,25.30,37.30,-49.00,-49.00,-49.00,16.10,-9.12,50.00,30.00)
    prop<-c(64, 62, 38, 37, 50, 30, 27, 10, 25, 39, 25,  6,  5, 25, 47, 24, 20,  2, 62, 40, 48, 60, 20, 40, 66, 57, 14, 25, 11,  0,  3,  5,  0,  0,  0, 14, 10, 11, 9,  1,  1, 34, 20, 90,  0,  0,  0,  0,  4,  5, 85,  6)
    group<-c("gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","gnc","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr","mr")
    mydata<-data.frame(lat,prop,group)
    newtype<-factor(group,levels=c("gnc","mr"))

图表:

    library(ggplot2)
    library(scales)

    ggplot(data=mydata,aes(x=lat,y=prop,colour=newtype))+
      geom_point(size=2.3) +
      stat_smooth(span=0.75,n=26,method="loess",aes(fill=newtype)) +
      theme_bw()+
      theme(
        panel.grid.minor=element_blank(),
        panel.grid.major=element_blank(),
        legend.position=c(0.15,0.85),
        legend.title=element_blank(),
        axis.text=element_text(size=17),
        axis.title=element_text(size=19),
        legend.text=element_text(size=17)
      )+
      scale_y_continuous(limit=c(0,NA),oob=squish)+ 
      scale_x_continuous(limit=c(-70,70),oob=squish,breaks=c(-60,-30,0,30,60))

0 个答案:

没有答案