Hi, I have a histogram with values logged to the base 10 hist(log10(x),breaks=60) How do I show the log values on the x-axis and a second x-axis showing the real values? Thanks -- Shane [[alternative HTML version deleted]]
Something like this? It does an extra y-axis but the principle is the same for an x-axis # Create the data to be graphed x<-1:10 y1<-x y2<-x^2 # Set the par values op <- par(las=1,xaxs="r",mai=c(1,0.75,1,1)) # Draw first plot plot(x,y1,xlim=c(0,10),ylim=c(0,10), ylab="y1", las = 1) title(main="Multiple Y-Axes in R") # Draw second plot par(new=TRUE) plot(x,y2,xlim=c(0,10),xaxt="n",yaxt="n",ylab="",pch=16) axis(4,at=c(0,20,40,60,80,100)) text(12, 50, "y2", srt = 270, xpd = TRUE) par(op) # reset par John Kane Kingston ON Canada> -----Original Message----- > From: careyshan at gmail.com > Sent: Tue, 26 Mar 2013 10:19:09 +0000 > To: r-help at r-project.org > Subject: [R] How do I show real values on a log10 histogram > > Hi, > > I have a histogram with values logged to the base 10 > > hist(log10(x),breaks=60) > > How do I show the log values on the x-axis and a second x-axis showing > the > real values? > > Thanks > > -- > Shane > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.____________________________________________________________ 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
On 13-03-26 6:19 AM, Shane Carey wrote:> Hi, > > I have a histogram with values logged to the base 10 > > hist(log10(x),breaks=60) > > How do I show the log values on the x-axis and a second x-axis showing the > real values? >I think it's hard to compute nice locations automatically, but if you compute them yourself, it's easy. Just use something like ticks <- c(0.1, 1, 10) axis(side=1, line=2, at=log10(ticks), labels=ticks) Duncan Murdoch
Hi maybe axis(3, (x)^10) Regards Petr> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Shane Carey > Sent: Tuesday, March 26, 2013 11:19 AM > To: r-help at r-project.org > Subject: [R] How do I show real values on a log10 histogram > > Hi, > > I have a histogram with values logged to the base 10 > > hist(log10(x),breaks=60) > > How do I show the log values on the x-axis and a second x-axis showing > the real values? > > Thanks > > -- > Shane > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Hi Shane.? I don't know.? I am not clear on what you are asking.? I would think that it would but can you supply some stripped-down code for people to have a look at?? See https://github.com/hadley/devtools/wiki/Reproducibility? and/or ?http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for some suggestions on how to do this. Oh and please don't reply in html. The R-help list strips html and while everything came through fine here, it can really jumble code if when the html is removed. BTW you only replied to me. It is a lot better to reply to the group especially as a lot of R-help people are a lot more knowledgeable than I am and you often can get faster responses.? I have included the R-help list in this response. John Kane Kingston ON Canada -----Original Message----- From: careyshan at gmail.com Sent: Tue, 26 Mar 2013 11:35:50 +0000 To: jrkrideau at inbox.com Subject: Re: [R] How do I show real values on a log10 histogram Hi John, I have four plots in a matrix format and Im already using par, if I use your code below the graph will not export as one of the four in the matrix, is there a way of overcoming this? Thanks for your help. Cheers On Tue, Mar 26, 2013 at 10:48 AM, John Kane <jrkrideau at inbox.com> wrote: Something like this? ?It does an extra y-axis but the principle is the same for an x-axis # Create the data to be graphed ? ? ? ? x<-1:10 ? ? ? ? y1<-x ? ? ? ? y2<-x^2 # Set the par values ? ? ? ? op ?<- par(las=1,xaxs="r",mai=c(1,0.75,1,1)) # Draw first plot ? ? ? ? plot(x,y1,xlim=c(0,10),ylim=c(0,10), ylab="y1", las = 1) ? ? ? ? title(main="Multiple Y-Axes in R") # Draw second plot ? ? ? ? par(new=TRUE) ? ? ? ? plot(x,y2,xlim=c(0,10),xaxt="n",yaxt="n",ylab="",pch=16) ? ? ? ? axis(4,at=c(0,20,40,60,80,100)) ? ? ? ? text(12, 50, "y2", srt = 270, xpd = TRUE) ? ? ? ? par(op) ?# reset par John Kane Kingston ON Canada > -----Original Message----- > From: careyshan at gmail.com > Sent: Tue, 26 Mar 2013 10:19:09 +0000 > To: r-help at r-project.org > Subject: [R] How do I show real values on a log10 histogram > > Hi, > > I have a histogram with values logged to the base 10 > > hist(log10(x),breaks=60) > > How do I show the log values on the x-axis and a second x-axis showing > the > real values? > > Thanks > > -- > Shane >> ? ? ? [[alternative HTML version deleted]]> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help [https://stat.ethz.ch/mailman/listinfo/r-help] > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html [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 [http://www.inbox.com/smileys] Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails -- Shane ____________________________________________________________ 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
Well, I don't think that is what Shane wants either but my suggestion is clearly wrong. I was reading the question as a dual axis not just a suplimentary , equivalent value axis. DUH. What I think he wants is what IIRC Petr orginally suggested which is this.. Create the data to be graphed x<-1:5 y1<-x y2<-x^2 # Set the par values # op <- par(las=1,xaxs="r",mai=c(1,1,1,1)) # Draw the plot plot(x,y1,xlim=c(0,5),ylim=c(0,5), ylab="y1", las = 1) title(main="Equvalent Axes in R") axis(3, labels = c("10", "100", "1,000", "10,000", "100,000"), at=1:5) text(12, 50, "y2", srt = 270, xpd = TRUE) par(op) # reset par John Kane Kingston ON Canada> -----Original Message----- > From: maechler at stat.math.ethz.ch > Sent: Wed, 27 Mar 2013 14:37:58 +0100 > To: careyshan at gmail.com > Subject: Re: [R] How do I show real values on a log10 histogram > >>>>>> Shane Carey <careyshan at gmail.com> >>>>>> on Tue, 26 Mar 2013 11:03:20 +0000 writes: > > > Yup, Ive tried all these things and I think Johns might be > > the best approach, > > well, :-) > you have not yet seen the following one : > > if(!require("sfsmisc")) install.packages("sfsmisc") > require("sfsmisc") > > ## the data: > set.seed(1); summary(x <- rlnorm(100, m = 2, sdl = 3)) > ## the plot (w/o x-axis) : > r <- hist(log10(x), xaxt = "n", xlab = "x [log scale]") > ## the nice axis: > axt <- axTicks(1) > eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE)) > > > Martin Maechler, > ETH Zurich > > > > thanks > > > On Tue, Mar 26, 2013 at 11:01 AM, PIKAL Petr > > <petr.pikal at precheza.cz> wrote: > > >> Hi > >> > >> maybe axis(3, (x)^10) > >> > >> Regards Petr > >> > >> > -----Original Message----- > From: > >> r-help-bounces at r-project.org [mailto:r-help-bounces at r- > > >> project.org] On Behalf Of Shane Carey > Sent: Tuesday, > >> March 26, 2013 11:19 AM > To: r-help at r-project.org > > >> Subject: [R] How do I show real values on a log10 > >> histogram > >> > > >> > Hi, > >> > > >> > I have a histogram with values logged to the base 10 > >> > > >> > hist(log10(x),breaks=60) > >> > > >> > How do I show the log values on the x-axis and a second > >> x-axis showing > the real values? > >> > > >> > Thanks > >> > > >> > -- > >> > Shane > >> > > >> > [[alternative HTML version deleted]] > >> > > >> > ______________________________________________ > > >> 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. > >> > > > > > -- > > Shane > > > [[alternative HTML version deleted]] > > > ______________________________________________ > > 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. > > ______________________________________________ > 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.____________________________________________________________ Receive Notifications of Incoming Messages Easily monitor multiple email accounts & access them with a click. Visit http://www.inbox.com/notifier and check it out!
Glad it worked. Sorry to mislead you so badly. John Kane Kingston ON Canada -----Original Message----- From: careyshan at gmail.com Sent: Wed, 27 Mar 2013 14:09:58 +0000 To: jrkrideau at inbox.com Subject: Re: [R] How do I show real values on a log10 histogram Yes, what I wanted was the original suggestion and that is what I went with. John, I found a solution around par also. There is a function called split.screen that allows you split the screen up, and also use par at the same time. Thanks everyone for all your help. Cheers On Wed, Mar 27, 2013 at 2:02 PM, John Kane <[1]jrkrideau at inbox.com> wrote: Well, I don't think that is what Shane wants either but my suggestion is clearly wrong. I was reading the question as a dual axis not just a suplimentary , equivalent value axis. DUH. What I think he wants is what IIRC Petr orginally suggested which is this.. Create the data to be graphed x<-1:5 y1<-x y2<-x^2 # Set the par values # op <- par(las=1,xaxs="r",mai=c(1,1,1,1)) # Draw the plot plot(x,y1,xlim=c(0,5),ylim=c(0,5), ylab="y1", las = 1) title(main="Equvalent Axes in R") axis(3, labels = c("10", "100", "1,000", "10,000", "100,000"), at=1:5) text(12, 50, "y2", srt = 270, xpd = TRUE) par(op) # reset par John Kane Kingston ON Canada > -----Original Message----- > From: [2]maechler at stat.math.ethz.ch > Sent: Wed, 27 Mar 2013 14:37:58 +0100 > To: [3]careyshan at gmail.com > Subject: Re: [R] How do I show real values on a log10 histogram > >>>>>> Shane Carey <[4]careyshan at gmail.com> >>>>>> on Tue, 26 Mar 2013 11:03:20 +0000 writes: > > > Yup, Ive tried all these things and I think Johns might be > > the best approach, > > well, :-) > you have not yet seen the following one : > > if(!require("sfsmisc")) install.packages("sfsmisc") > require("sfsmisc") > > ## the data: > set.seed(1); summary(x <- rlnorm(100, m = 2, sdl = 3)) > ## the plot (w/o x-axis) : > r <- hist(log10(x), xaxt = "n", xlab = "x [log scale]") > ## the nice axis: > axt <- axTicks(1) > eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE)) > > > Martin Maechler, > ETH Zurich > > > > thanks > > > On Tue, Mar 26, 2013 at 11:01 AM, PIKAL Petr > > <[5]petr.pikal at precheza.cz> wrote: > > >> Hi > >> > >> maybe axis(3, (x)^10) > >> > >> Regards Petr > >> > >> > -----Original Message----- > From: > >> [6]r-help-bounces at r-project.org [mailto:[7]r-help-bounces at r- > > >> [8]project.org] On Behalf Of Shane Carey > Sent: Tuesday, > >> March 26, 2013 11:19 AM > To: [9]r-help at r-project.org > > >> Subject: [R] How do I show real values on a log10 > >> histogram > >> > > >> > Hi, > >> > > >> > I have a histogram with values logged to the base 10 > >> > > >> > hist(log10(x),breaks=60) > >> > > >> > How do I show the log values on the x-axis and a second > >> x-axis showing > the real values? > >> > > >> > Thanks > >> > > >> > -- > >> > Shane > >> > > >> > [[alternative HTML version deleted]] > >> > > >> > ______________________________________________ > > >> [10]R-help at r-project.org mailing list > > >> [11]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do > >> read the posting guide [12]http://www.R-project.org/posting- > >> > guide.html > and provide commented, minimal, > >> self-contained, reproducible code. > >> > > > > > -- > > Shane > > > [[alternative HTML version deleted]] > > > ______________________________________________ > > [13]R-help at r-project.org mailing list > > [14]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do > > read the posting guide > > [15]http://www.R-project.org/posting-guide.html and provide > > commented, minimal, self-contained, reproducible code. > > ______________________________________________ > [16]R-help at r-project.org mailing list > [17]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > [18]http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ Receive Notifications of Incoming Messages Easily monitor multiple email accounts & access them with a click. Visit [19]http://www.inbox.com/notifier and check it out! -- Shane _________________________________________________________________ [20]3D Earth Screensaver Preview Free 3D Earth Screensaver Watch the Earth right on your desktop! Check it out at [21]www.inbox.com/earth References 1. mailto:jrkrideau at inbox.com 2. mailto:maechler at stat.math.ethz.ch 3. mailto:careyshan at gmail.com 4. mailto:careyshan at gmail.com 5. mailto:petr.pikal at precheza.cz 6. mailto:r-help-bounces at r-project.org 7. mailto:r-help-bounces at r- 8. http://project.org/ 9. mailto:r-help at r-project.org 10. mailto:R-help at r-project.org 11. https://stat.ethz.ch/mailman/listinfo/r-help 12. http://www.R-project.org/posting- 13. mailto:R-help at r-project.org 14. https://stat.ethz.ch/mailman/listinfo/r-help 15. http://www.R-project.org/posting-guide.html 16. mailto:R-help at r-project.org 17. https://stat.ethz.ch/mailman/listinfo/r-help 18. http://www.R-project.org/posting-guide.html 19. http://www.inbox.com/notifier 20. http://www.inbox.com/earth 21. http://www.inbox.com/earth