How to match legend colors and plot colors in overlapping area plots in ggplot2

后端 未结 2 1154
不思量自难忘°
不思量自难忘° 2021-01-27 08:26

I have the following data:

head(MP_rates_dateformat) 
       Month repo revrepo bankrate CRR Callrate  WPI GDP  FED
1 2001-04-01 9.00    6.75        7 8.0     7.         


        
2条回答
  •  梦谈多话
    2021-01-27 09:18

    Finally Got it!

    library("tidyr")
    
    long_DF<- MP_rates_dateformat[,1:3] %>% gather(variable, value, -Month)
    head(long_DF)
    
        Month variable value
    1 2001-04-01     repo  9.00
    2 2001-05-01     repo  8.75
    3 2001-06-01     repo  8.50
    4 2001-07-01     repo  8.50
    5 2001-08-01     repo  8.50
    6 2001-09-01     repo  8.50
    
    library("ggplot2") 
    
    ggplot(data = long_DF, aes(x = Month)) +
    geom_area(aes(y = value, fill = variable), position = "identity") +   labs(fill="") + xlab('\nYears') + ylab('LAF Rates (%)\n') + labs(title="Overlapping - Repo & Reverse Repo\n")
    

提交回复
热议问题