2

I'm trying to plot a scatterplot with errorbars together with a barplot. Both variables have a very different range (scatterplot 0 - 20000+; bar chart 0-1). So I want to create a plot with both graphs in it, with two different y-axes. This is what I've got so far:

ggplot(data, aes(x=seaname, y=chao2)) + geom_bar(stat="identity", 
aes(x=seaname, y=compl, colour=major_sea)) + geom_point(aes(colour=major_sea))
+ geom_errorbar(aes(ymin=chao2_lower, ymax=chao2_upper,
colour=major_sea)) + theme(axis.text.x=element_text(angle=90,
vjust=0.5, size=9))

Just to clarify: I don't want two graphs represented below each other. I would like them in the same, single graph. Anyone who has experience with this kind of problem?

Cheers!!

tonytonov
  • 25,060
  • 16
  • 82
  • 98
  • anyone who experienced this kind of problem most likely gave up: dual axes are not implemented in ggplot2 (and for good reasons). – baptiste Apr 21 '14 at 11:01
  • @MasatoNakazawa, your link includes the "]" and that may cause people to think that the link is dead. – Eduardo Aug 20 '14 at 16:17
  • 2
    Even though it may not be a good practice, it can be done. See [link](http://rpubs.com/kohske/dual_axis_in_ggplot2). @Eduardo Thanks for letting me know about the link. – Masato Nakazawa Aug 20 '14 at 16:27

0 Answers0