Dear All, I have this script: dat <- data.frame(Month = hstat$Date,C_avg = hstat$C.avg,C_stdev hstat$C.stdev) ggplot(data = dat, aes(x = Month, y = C_avg, ymin = C_avg - C_stdev, ymax C_avg + C_stdev)) + geom_point() + geom_line() + geom_errorbar() dat <- data.frame(Month = hstat$Date,K_avg = hstat$K.avg,K_stdev hstat$K.stdev) ggplot(data = dat, aes(x = Month, y = K_avg, ymin = K_avg - K_stdev, ymax K_avg + K_stdev)) + geom_point() + geom_line() + geom_errorbar() dat <- data.frame(Month = hstat$Date,S_avg = hstat$S.avg,S_stdev hstat$S.stdev) ggplot(data = dat, aes(x = Month, y = S_avg, ymin = S_avg - S_stdev, ymax S_avg + S_stdev)) + geom_point() + geom_line() + geom_errorbar() Running the script generates 3 separate graphs, how can I output them next to each other? Thanks -- View this message in context: http://r.789695.n4.nabble.com/ggplot-output-tp3027026p3027026.html Sent from the R help mailing list archive at Nabble.com.
Have you tried ?split.screen ________________________________ Annemarie Eigenhuis, MSc University of Amsterdam Department of Psychology, clinical area Roetersstraat 15 1018 WB Amsterdam The Netherlands phone: +31(0)205256815 email: a.eigenhuis at uva.nl -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of ashz Sent: donderdag 4 november 2010 14:37 To: r-help at r-project.org Subject: [R] ggplot output Dear All, I have this script: dat <- data.frame(Month = hstat$Date,C_avg = hstat$C.avg,C_stdev hstat$C.stdev) ggplot(data = dat, aes(x = Month, y = C_avg, ymin = C_avg - C_stdev, ymax = C_avg + C_stdev)) + geom_point() + geom_line() + geom_errorbar() dat <- data.frame(Month = hstat$Date,K_avg = hstat$K.avg,K_stdev hstat$K.stdev) ggplot(data = dat, aes(x = Month, y = K_avg, ymin = K_avg - K_stdev, ymax = K_avg + K_stdev)) + geom_point() + geom_line() + geom_errorbar() dat <- data.frame(Month = hstat$Date,S_avg = hstat$S.avg,S_stdev hstat$S.stdev) ggplot(data = dat, aes(x = Month, y = S_avg, ymin = S_avg - S_stdev, ymax = S_avg + S_stdev)) + geom_point() + geom_line() + geom_errorbar() Running the script generates 3 separate graphs, how can I output them next to each other? Thanks -- View this message in context: http://r.789695.n4.nabble.com/ggplot-output-tp3027026p3027026.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.
The easiest way it to create one long dataset with four variables: Month, avg, stdev and type. Type will be either K, C or S. Then you just need to add some facetting to your code ggplot(data = dat, aes(x = Month, y = avg, ymin = avg - stdev, ymax avg + stdev)) + geom_point() + geom_line() + geom_errorbar() + facet_wrap(~type, nrow = 1) HTH, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey> -----Oorspronkelijk bericht----- > Van: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Namens ashz > Verzonden: donderdag 4 november 2010 14:37 > Aan: r-help at r-project.org > Onderwerp: [R] ggplot output > > > Dear All, > > I have this script: > > dat <- data.frame(Month = hstat$Date,C_avg = hstat$C.avg,C_stdev > hstat$C.stdev) > ggplot(data = dat, aes(x = Month, y = C_avg, ymin = C_avg - > C_stdev, ymax = C_avg + C_stdev)) + > geom_point() + > geom_line() + > geom_errorbar() > > dat <- data.frame(Month = hstat$Date,K_avg = hstat$K.avg,K_stdev > hstat$K.stdev) > ggplot(data = dat, aes(x = Month, y = K_avg, ymin = K_avg - > K_stdev, ymax = K_avg + K_stdev)) + > geom_point() + > geom_line() + > geom_errorbar() > > dat <- data.frame(Month = hstat$Date,S_avg = hstat$S.avg,S_stdev > hstat$S.stdev) > ggplot(data = dat, aes(x = Month, y = S_avg, ymin = S_avg - > S_stdev, ymax = S_avg + S_stdev)) + > geom_point() + > geom_line() + > geom_errorbar() > > Running the script generates 3 separate graphs, how can I > output them next to each other? > > Thanks > > -- > View this message in context: > http://r.789695.n4.nabble.com/ggplot-output-tp3027026p3027026.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. >
Dear Thierry, Your solution looks very elgant but I can not find a proper example. Can you provide me one? Thx -- View this message in context: http://r.789695.n4.nabble.com/ggplot-output-tp3027026p3027108.html Sent from the R help mailing list archive at Nabble.com.
Have a look at the ggplot2 website. It has a lot of examples http://had.co.nz/ggplot2/ look at the bottom of this page for facet_grid() and facet_wrap() http://had.co.nz/ggplot2/facet_wrap.html direct link to facet_wrap() ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey> -----Oorspronkelijk bericht----- > Van: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Namens ashz > Verzonden: donderdag 4 november 2010 15:32 > Aan: r-help at r-project.org > Onderwerp: Re: [R] ggplot output > > > Dear Thierry, > > Your solution looks very elgant but I can not find a proper example. > > Can you provide me one? > > Thx > > -- > View this message in context: > http://r.789695.n4.nabble.com/ggplot-output-tp3027026p3027108.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. >
The other way (in the same spirit as par(mfrow = ...) in base graphics) is to use the grid.arrange function in the gridExtra package. See it's documentation for examples. On Nov 4, 2010, at 9:36 AM, ashz wrote:> > Dear All, > > I have this script: > > dat <- data.frame(Month = hstat$Date,C_avg = hstat$C.avg,C_stdev > hstat$C.stdev) > ggplot(data = dat, aes(x = Month, y = C_avg, ymin = C_avg - C_stdev, ymax > C_avg + C_stdev)) + > geom_point() + > geom_line() + > geom_errorbar() > > dat <- data.frame(Month = hstat$Date,K_avg = hstat$K.avg,K_stdev > hstat$K.stdev) > ggplot(data = dat, aes(x = Month, y = K_avg, ymin = K_avg - K_stdev, ymax > K_avg + K_stdev)) + > geom_point() + > geom_line() + > geom_errorbar() > > dat <- data.frame(Month = hstat$Date,S_avg = hstat$S.avg,S_stdev > hstat$S.stdev) > ggplot(data = dat, aes(x = Month, y = S_avg, ymin = S_avg - S_stdev, ymax > S_avg + S_stdev)) + > geom_point() + > geom_line() + > geom_errorbar() > > Running the script generates 3 separate graphs, how can I output them next > to each other? > > Thanks > > -- > View this message in context: http://r.789695.n4.nabble.com/ggplot-output-tp3027026p3027026.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.