0

I am trying to make an overlaid plot, having 2 y-axes. I want one plot to be a bar plot and the other to be a line plot. I know how to do this in ggplot2 (i.e. ggplot2 overlay of barplot and line plot), but I would like to learn how to do this using the ggpubr package. I'd be grateful for any insight anyone can provide! I know is is an elementary question, so thank you for bearing with me!

In the interest of clarity, I have included the sample data frame provided by @SpencerTrinh in the linked question.

# Sample data
df1 <- data.frame(frax = c(16,30,60,64), solvb = c(0,0,100,100))
df2 <- data.frame(type = factor(c("mascot","mstat"), levels = c("mascot","mstat")), 
                 frax = c(30,35,40,45,50,55), phos = c(542,413,233,500,600,650))

This is what I'm looking for: enter image description here

Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
DMC
  • 63
  • 8
  • I'm not familiar with ggpubr, but it's worth noting that the ggplot2 solution was written before ggplot supported a secondary axis with the [sec_axis argument](https://ggplot2.tidyverse.org/reference/sec_axis.html), and you may have some luck with that. – Dubukay Jan 25 '21 at 22:10
  • Hey @Dubukay! Yeah - I've been messing around with that but I think I'm missing something earlier, as I keep getting an error saying I can't "add to a ggplot object." I can make both the line plot and the bar plot on their own so I know the issue is in trying to combine them. I'm stumped – DMC Jan 25 '21 at 22:27

0 Answers0