在ggplot2的区域图表中添加图例标题

时间:2018-03-20 13:11:32

标签: r ggplot2 data-visualization stacked-area-chart

我正在尝试为R,gplot2中的以下代码添加图例以获取堆积区域图表:

plot1<-ggplot(data=agegenderdata,
              aes(x=agegenderdata$Year,
                  y=agegenderdata$`Obesity Inpatients`,
                  fill=agegenderdata$`Age Category`))
plot1withGeom <- plot1 + geom_area(aes(colour=agegenderdata$`Age Category`, fill=agegenderdata$`Age Category`)) 

plot1withGeom + labs(x = "Year", y = "Obesity Inpatients", title = "graph" ) 

然而,当在线检查并尝试使用不同的方法来更改图例标题时,我运气不佳。有人可以帮忙。

非常感谢。

1 个答案:

答案 0 :(得分:0)

要更改图例的标题,请使用实验和图例对应的美学。

例如:

export class ArtistComponent implements OnInit {
  private repertoire$;
  private repertoireSubject;
  constructor(
    private route: ActivatedRoute,
    private service: ArtistService
  ) {
    this.getRepertoire().subscribe(
      songs => this.repertoireSubject.next(songs)
    );
  }

  getRepertoire() {
    return this.route.paramMap
      .switchMap((params: ParamMap) =>
      this.service.fetchRepertoire(params.get('id')));
  }

  //THIS IS WHERE I'M HAVING TROUBLE
  delete(id): void {
    this.repertoireSubject.next(
      this.repertoireSubject.getValue().filter(song => (song.id !== id))
    );
    // TODO remove song from repertoire API
  }

  ngOnInit() {
    this.repertoireSubject = new BehaviorSubject<any>(null);
    this.repertoire$ = this.repertoireSubject.asObservable();
  }

}
相关问题