Re: [R] plotting two histograms on one plot with hist function
-Original Message- From: mb...@sun.ac.za Sent: Wed, 27 Jun 2012 08:32:24 +0200 To: jrkrid...@inbox.com, ke...@math.montana.edu Subject: RE: [R] plotting two histograms on one plot with hist function Thank you for all the advice! After mailing the question, I actually found a function called multhist (plotrix package) that plots two data sets (in single list) on a single histogram. Trust Jim to be there ahead of everyone! The script is as follows: #I listed to two data sets in “long” format in a .csv file input <- read.csv(file= "list.csv", h = TRUE) library(plotrix) #to plot two data sets on one histogram multhist(input, xlab="Label”, ylab="Frequency", col=c("Red", "Green"), ylim=c(0,50)) #to add a legend to the top left corner legend("topleft", c("Dataset 1","Data set 2"), cex=0.6,bty="n", fill=c("Red","Green")) Thanks again for the help! From: John Kane [mailto:jrkrid...@inbox.com] Sent: 26 June 2012 23:27 To: ilai Cc: Blignaut, M, Mej ; r-help@r-project.org Subject: Re: [R] plotting two histograms on one plot with hist function Oh, I had not thought of it in those terms. It does make sense now. John Kane Kingston ON Canada -Original Message- From: ke...@math.montana.edu Sent: Tue, 26 Jun 2012 10:57:31 -0600 To: jrkrid...@inbox.com Subject: Re: [R] plotting two histograms on one plot with hist function On Tue, Jun 26, 2012 at 10:02 AM, John Kane <[1]jrkrid...@inbox.com> wrote: Why not just plot the two histograms on the same scale in a 2 panel plot? I think OP request was "for comparison". Two panels may do, but why not a barplot of the histograms in the same panel ? barplot( rbind( hist(rbeta(30,2,4),breaks=seq(0,1,.1),plot=F)$counts, hist(rbeta(30,6,8),breaks=seq(0,1,.1),plot=F)$counts), beside=T) see str(hist(yourdata)) or ?hist Cheers Ilai John Kane Kingston ON Canada > -Original Message- > From: [2]mb...@sun.ac.za > Sent: Tue, 26 Jun 2012 15:24:55 +0200 > To: [3]r-help@r-project.org > Subject: [R] plotting two histograms on one plot with hist function > > I would like to plot two data sets (frequency (y-axis) of mean values for > 0-1(x=axis)) on a single histogram for comparison. The hist() only allow > the overlay of two histograms, and although barplot() allows beside=TRUE, > it does not show frequency values (like hist) but rather all of the > values. Is there any way that I can use the hist() to plot two data sets > similar to the barplot(). Any help or advice will be appreciated! > > Kind regards, > Marguerite > > > > > > > E-pos vrywaringsklousule > > Hierdie e-pos mag vertroulike inligting bevat en mag regtens > geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit > geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u > hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, > versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per > telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie > aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit > hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos > nie. > > E-mail disclaimer > > This e-mail may contain confidential information and may...{{dropped:11}} > > __ > [4]R-help@r-project.org mailing list > [5]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > [6]http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at [7]http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ [8]R-help@r-project.org mailing list [9]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide [10]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Free Online Photosharing - Share your photos online with
Re: [R] plotting two histograms on one plot with hist function
Thank you for all the advice! After mailing the question, I actually found a function called multhist (plotrix package) that plots two data sets (in single list) on a single histogram. The script is as follows: #I listed to two data sets in âlongâ format in a .csv file input <- read.csv(file= "list.csv", h = TRUE) library(plotrix) #to plot two data sets on one histogram multhist(input, xlab="Labelâ, ylab="Frequency", col=c("Red", "Green"), ylim=c(0,50)) #to add a legend to the top left corner legend("topleft", c("Dataset 1","Data set 2"), cex=0.6,bty="n", fill=c("Red","Green")) Thanks again for the help! From: John Kane [mailto:jrkrid...@inbox.com] Sent: 26 June 2012 23:27 To: ilai Cc: Blignaut, M, Mej ; r-help@r-project.org Subject: Re: [R] plotting two histograms on one plot with hist function Oh, I had not thought of it in those terms. It does make sense now. John Kane Kingston ON Canada -Original Message----- From: ke...@math.montana.edu Sent: Tue, 26 Jun 2012 10:57:31 -0600 To: jrkrid...@inbox.com Subject: Re: [R] plotting two histograms on one plot with hist function On Tue, Jun 26, 2012 at 10:02 AM, John Kane mailto:jrkrid...@inbox.com>> wrote: Why not just plot the two histograms on the same scale in a 2 panel plot? I think OP request was "for comparison". Two panels may do, but why not a barplot of the histograms in the same panel ? barplot( rbind( hist(rbeta(30,2,4),breaks=seq(0,1,.1),plot=F)$counts, hist(rbeta(30,6,8),breaks=seq(0,1,.1),plot=F)$counts), beside=T) see str(hist(yourdata)) or ?hist Cheers Ilai John Kane Kingston ON Canada > -Original Message- > From: mb...@sun.ac.za<mailto:mb...@sun.ac.za> > Sent: Tue, 26 Jun 2012 15:24:55 +0200 > To: r-help@r-project.org<mailto:r-help@r-project.org> > Subject: [R] plotting two histograms on one plot with hist function > > I would like to plot two data sets (frequency (y-axis) of mean values for > 0-1(x=axis)) on a single histogram for comparison. The hist() only allow > the overlay of two histograms, and although barplot() allows beside=TRUE, > it does not show frequency values (like hist) but rather all of the > values. Is there any way that I can use the hist() to plot two data sets > similar to the barplot(). Any help or advice will be appreciated! > > Kind regards, > Marguerite > > > > > > > E-pos vrywaringsklousule > > Hierdie e-pos mag vertroulike inligting bevat en mag regtens > geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit > geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u > hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, > versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per > telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie > aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit > hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos > nie. > > E-mail disclaimer > > This e-mail may contain confidential information and may...{{dropped:11}} > > __ > R-help@r-project.org<mailto:R-help@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. GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk⢠and most webmails __ R-help@r-project.org<mailto:R-help@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 Online Photosharing - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! E-pos vrywaringsklousule Hierdie e-pos mag vertroulike inligting bevat en mag regtens geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit hierdie e-pos en/
Re: [R] plotting two histograms on one plot with hist function
Oh, I had not thought of it in those terms. It does make sense now. John Kane Kingston ON Canada -Original Message- From: ke...@math.montana.edu Sent: Tue, 26 Jun 2012 10:57:31 -0600 To: jrkrid...@inbox.com Subject: Re: [R] plotting two histograms on one plot with hist function On Tue, Jun 26, 2012 at 10:02 AM, John Kane <[1]jrkrid...@inbox.com> wrote: Why not just plot the two histograms on the same scale in a 2 panel plot? I think OP request was "for comparison". Two panels may do, but why not a barplot of the histograms in the same panel ? barplot( rbind( hist(rbeta(30,2,4),breaks=seq(0,1,.1),plot=F)$counts, hist(rbeta(30,6,8),breaks=seq(0,1,.1),plot=F)$counts), beside=T) see str(hist(yourdata)) or ?hist Cheers Ilai John Kane Kingston ON Canada > -Original Message- > From: [2]mb...@sun.ac.za > Sent: Tue, 26 Jun 2012 15:24:55 +0200 > To: [3]r-help@r-project.org > Subject: [R] plotting two histograms on one plot with hist function > > I would like to plot two data sets (frequency (y-axis) of mean values for > 0-1(x=axis)) on a single histogram for comparison. The hist() only allow > the overlay of two histograms, and although barplot() allows beside=TRUE, > it does not show frequency values (like hist) but rather all of the > values. Is there any way that I can use the hist() to plot two data sets > similar to the barplot(). Any help or advice will be appreciated! > > Kind regards, > Marguerite > > > > > > > E-pos vrywaringsklousule > > Hierdie e-pos mag vertroulike inligting bevat en mag regtens > geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit > geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u > hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, > versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per > telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie > aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit > hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos > nie. > > E-mail disclaimer > > This e-mail may contain confidential information and may...{{dropped:11}} > > __ > [4]R-help@r-project.org mailing list > [5]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > [6]http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at [7]http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ [8]R-help@r-project.org mailing list [9]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide [10]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Free Online Photosharing - Share your photos online with your friends and family! Visit [11]http://www.inbox.com/photosharing to find out more! References 1. mailto:jrkrid...@inbox.com 2. mailto:mb...@sun.ac.za 3. mailto:r-help@r-project.org 4. mailto:R-help@r-project.org 5. https://stat.ethz.ch/mailman/listinfo/r-help 6. http://www.R-project.org/posting-guide.html 7. http://www.inbox.com/smileys 8. mailto:R-help@r-project.org 9. https://stat.ethz.ch/mailman/listinfo/r-help 10. http://www.R-project.org/posting-guide.html 11. http://www.inbox.com/photosharing __ R-help@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.
Re: [R] plotting two histograms on one plot with hist function
On Tue, Jun 26, 2012 at 10:02 AM, John Kane wrote: > Why not just plot the two histograms on the same scale in a 2 panel plot? > I think OP request was "for comparison". Two panels may do, but why not a barplot of the histograms in the same panel ? barplot( rbind( hist(rbeta(30,2,4),breaks=seq(0,1,.1),plot=F)$counts, hist(rbeta(30,6,8),breaks=seq(0,1,.1),plot=F)$counts), beside=T) see str(hist(yourdata)) or ?hist Cheers Ilai > John Kane > Kingston ON Canada > > > > -Original Message- > > From: mb...@sun.ac.za > > Sent: Tue, 26 Jun 2012 15:24:55 +0200 > > To: r-help@r-project.org > > Subject: [R] plotting two histograms on one plot with hist function > > > > I would like to plot two data sets (frequency (y-axis) of mean values for > > 0-1(x=axis)) on a single histogram for comparison. The hist() only allow > > the overlay of two histograms, and although barplot() allows beside=TRUE, > > it does not show frequency values (like hist) but rather all of the > > values. Is there any way that I can use the hist() to plot two data sets > > similar to the barplot(). Any help or advice will be appreciated! > > > > Kind regards, > > Marguerite > > > > > > > > > > > > > > E-pos vrywaringsklousule > > > > Hierdie e-pos mag vertroulike inligting bevat en mag regtens > > geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit > > geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u > > hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, > > versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per > > telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie > > aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit > > hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos > > nie. > > > > E-mail disclaimer > > > > This e-mail may contain confidential information and may...{{dropped:11}} > > > > __ > > R-help@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. > > > GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at > http://www.inbox.com/smileys > Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk and > most webmails > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] plotting two histograms on one plot with hist function
Why not just plot the two histograms on the same scale in a 2 panel plot? John Kane Kingston ON Canada > -Original Message- > From: mb...@sun.ac.za > Sent: Tue, 26 Jun 2012 15:24:55 +0200 > To: r-help@r-project.org > Subject: [R] plotting two histograms on one plot with hist function > > I would like to plot two data sets (frequency (y-axis) of mean values for > 0-1(x=axis)) on a single histogram for comparison. The hist() only allow > the overlay of two histograms, and although barplot() allows beside=TRUE, > it does not show frequency values (like hist) but rather all of the > values. Is there any way that I can use the hist() to plot two data sets > similar to the barplot(). Any help or advice will be appreciated! > > Kind regards, > Marguerite > > > > > > > E-pos vrywaringsklousule > > Hierdie e-pos mag vertroulike inligting bevat en mag regtens > geprivilegeerd wees en is slegs bedoel vir die persoon aan wie dit > geadresseer is. Indien u nie die bedoelde ontvanger is nie, word u > hiermee in kennis gestel dat u hierdie dokument geensins mag gebruik, > versprei of kopieer nie. Stel ook asseblief die sender onmiddellik per > telefoon in kennis en vee die e-pos uit. Die Universiteit aanvaar nie > aanspreeklikheid vir enige skade, verlies of uitgawe wat voortspruit uit > hierdie e-pos en/of die oopmaak van enige l?ers aangeheg by hierdie e-pos > nie. > > E-mail disclaimer > > This e-mail may contain confidential information and may...{{dropped:11}} > > __ > R-help@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. GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@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.