xin wei
2012-Aug-05 00:17 UTC
[R] how to put barchart and line chart in the same plot in ggplot2
dear userR: I am trying to plot two dependent variables in the same plot in ggplot2. because these two variables have very different magnitude, I have to use a second Y axis. I hope one variable to be line and the other to be barchart. The x axis is continuous. Yet since I have to make barchart, I guess I have to treat it as discrete or categorical. I have been google searching for the whole afternoon but do not have any clue. Can anyone give me a direction (not have to be a complete answer...)? many thanks -- View this message in context: http://r.789695.n4.nabble.com/how-to-put-barchart-and-line-chart-in-the-same-plot-in-ggplot2-tp4639194.html Sent from the R help mailing list archive at Nabble.com.
Jim Lemon
2012-Aug-05 07:55 UTC
[R] how to put barchart and line chart in the same plot in ggplot2
On 08/05/2012 10:17 AM, xin wei wrote:> dear userR: > I am trying to plot two dependent variables in the same plot in ggplot2. > because these two variables have very different magnitude, I have to use a > second Y axis. I hope one variable to be line and the other to be barchart. > The x axis is continuous. Yet since I have to make barchart, I guess I have > to treat it as discrete or categorical. > I have been google searching for the whole afternoon but do not have any > clue. > Can anyone give me a direction (not have to be a complete answer...)? >Hi xin wei, If you're desperate, have a look at twoord.plot in the plotrix package. Jim
John Kane
2012-Aug-05 14:36 UTC
[R] how to put barchart and line chart in the same plot in ggplot2
As far as I understand ggplot2, you cannot do it. ggplot2 is pretty much designed to NOT allow two different sets of data with different y axes in the same plot. Doing this is generally considered very bad practice. I'd suggest looking into perhaps using a 2X1 or X2 grid and plotting the two sets perhaps beside or above/below Have a look at http://stackoverflow.com/questions/9490482/combined-plot-of-ggplot2-not-in-a-single-plot-using-par-or-layout-functio # see http://stackoverflow.com/questions/8615530/place-title-of-multiplot-panel-with-ggplot2 for an example Kingston ON Canada> -----Original Message----- > From: xinwei at stat.psu.edu > Sent: Sat, 4 Aug 2012 17:17:58 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] how to put barchart and line chart in the same plot in > ggplot2 > > dear userR: > I am trying to plot two dependent variables in the same plot in ggplot2. > because these two variables have very different magnitude, I have to use > a > second Y axis. I hope one variable to be line and the other to be > barchart. > The x axis is continuous. Yet since I have to make barchart, I guess I > have > to treat it as discrete or categorical. > I have been google searching for the whole afternoon but do not have any > clue. > Can anyone give me a direction (not have to be a complete answer...)? > > many thanks > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/how-to-put-barchart-and-line-chart-in-the-same-plot-in-ggplot2-tp4639194.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!