在R中编辑图例的文本,形状和颜色

时间:2018-08-02 04:59:35

标签: r ggplot2 legend

我使用以下代码制作了一个带有集成geom_line的散点图进行比较:

ggplot() +
  geom_text_repel(data=MovieData, direction = "y", hjust= 0.5,  
                  aes(x=Year, y=Income, color=Genre,label=MovieData$Movie)) +
  geom_point(data=MovieData, size=3, aes(x=Year, y=Income, color=Genre)) + 
  scale_color_brewer(palette = "Set1") + 
  theme_minimal() +
  ylab("Income (Miillion EGP)") + 
  scale_x_continuous(labels=c("1998","2003","2008","2013","2018")) +
  ggtitle("Movie income and genre by year") +
  geom_line(data=AhmadHelmyMovies, size= 1.5 , color= "dodgerblue3", alpha=0.5,
            aes(Year,Income)) +
  geom_point(data=AhmadHelmyMovies, size= 5,
             aes(Year,Income, pch="Ahmad Helmy Trend"), color="red") + 
  geom_line(data=ElsaqqaMovies, size= 1.5 , color= "red3", alpha=0.5,
          aes(Year,Income)) +
  geom_point(data=ElsaqqaMovies, size= 5 ,
             aes(Year,Income, pch="Ahmad Elsaqqa Trend"), color="blue") 

Resulting graph

现在我对此图有多个问题:

a。首先,传说似乎与多个形状重叠红色圆圈

b。其次,与形状(pch参数)相关的图例以错误的方式上色,我为形状分配了颜色,并希望它们与图例匹配

c。有什么建议可以改善图表吗?

现在我仅在最近的两周内学习了R,所以请对我轻松理解术语和代码,并为我进行解释。提前致谢。

0 个答案:

没有答案