0

Hi I want to show in the same graph a barplot and a line. They have the same x axis but different y axis.

Just the barplot looks like this:

barplot

and when I use this:

ggplot()+ geom_line(data=avdischarge, aes(x= monthyr, y= Avdischarge))+
  geom_bar(data= melt, aes(x=monthyr, y= value, fill= Compound ), stat= "identity")+
  scale_y_continuous("Average discharge", sec.axis = sec_axis(~./100, name = "Concentration"))

I get this plot:

Combined plot

What can I do so the barplot appears as the first picture? and not like a tiny thing below the geom_line?

Also, How can I add just the legend of the line?

user195366
  • 465
  • 2
  • 13
  • 5
    Possible duplicate of [Plot with 2 y axes, one y axis on the left, and another y axis on the right](https://stackoverflow.com/questions/3099219/plot-with-2-y-axes-one-y-axis-on-the-left-and-another-y-axis-on-the-right) – erc Feb 20 '19 at 13:44
  • Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Feb 20 '19 at 14:24

0 Answers0