0

I am trying to combine two different data series into the same line chart with two y-axes. How could I accomplish this? The code and plots are below:

A <- ggplot(Alldata, aes(Date)) + 
       geom_tile(aes(alpha = Recession, y = 1), fill = "grey", height = Inf) + 
       scale_alpha_continuous(range = c(0, 1), breaks = c(0, 1))+ 
      geom_line(aes(y = INFEX), col = 'blue', size = .8)+ 
      ylab("Inflation Expectations") 

B <- ggplot(Alldata, aes(Date)) + 
      geom_tile(aes(alpha = Recession, y = 1), fill = "grey", height = Inf) + 
      scale_alpha_continuous(range = c(0, 1), breaks = c(0, 1))+ 
      geom_line(aes(y = CLI), col = 'green', size = .8)+ ylab("CLI") 

A | B

ggplots

enter image description here

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
MacroChair
  • 47
  • 5
  • Hi @Koalaconomist. Adding a second y axis in ggplot is possible. The linked duplicate question gives an example of how to do it. Look at the documentation for `?ggplot2::scale_y_continuous` and in particular the `sec.axis` parameter – Allan Cameron Oct 04 '21 at 14:22

0 Answers0