# Axis/Ticks/Scale

10 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Axis/Ticks/Scale

 Dear All, Apologies for this simple question and thanks in advance for any help given. Suppose I wanted to plot 1 million observations and produce the command plot(rnorm(1000000)) The labels of the xaxis are 0, e+00 2 e+05 etc. These are clearly not very attractive (The plots are for a PhD. thesis). I would like the axes to be 0,2,4,6,8,10 with a *10^5 on the right hand side. Is there a simple command for this? Best Wishes Roger ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Axis/Ticks/Scale

 Here is one way to do it with a smaller set of data, but the 'range' is the same: > x <- c(1,1000,1000000) > y <- pretty(range(x)) > y [1] 0e+00 2e+05 4e+05 6e+05 8e+05 1e+06 > plot(x,1:3,xaxt='n', xlab="X * 10^5") > axis(1, at=y, labels=y/100000) > On 12/28/05, [hidden email] <[hidden email]> wrote: > > > Dear All, > > Apologies for this simple question and thanks in advance for any help > given. > > Suppose I wanted to plot 1 million observations and produce the command > > plot(rnorm(1000000)) > > The labels of the xaxis are 0, e+00 2 e+05 etc. These are clearly not very > attractive (The plots are for a PhD. thesis). > > I would like the axes to be 0,2,4,6,8,10 with a *10^5 on the right hand > side. > > Is there a simple command for this? > > Best Wishes > > Roger > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html> -- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve?         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Axis/Ticks/Scale

 In reply to this post by R.C.GILL Try this: x <- c(1, 1e6); y <- 0:1 par(mar = c(5, 4, 4, 5) + 0.1)  # make room at the right plot(x, y, axes = FALSE) box() axis(2) axis(1, at = 0:5 * 2 * 1e5, labels = 0:5 * 2) mtext(text = expression(phantom(0)%*%10^5),        side = 1, line = 1, at = 11.0 * 1e5) Peter Ehlers [hidden email] wrote: > Dear All, > > Apologies for this simple question and thanks in advance for any help given. > > Suppose I wanted to plot 1 million observations and produce the command > > plot(rnorm(1000000)) > > The labels of the xaxis are 0, e+00 2 e+05 etc. These are clearly not very > attractive (The plots are for a PhD. thesis). > > I would like the axes to be 0,2,4,6,8,10 with a *10^5 on the right hand > side. > > Is there a simple command for this? > > Best Wishes > > Roger > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Axis/Ticks/Scale

 In reply to this post by R.C.GILL On Wed, 2005-12-28 at 20:15 +0000, [hidden email] wrote: > Dear All, > > Apologies for this simple question and thanks in advance for any help > given. > > Suppose I wanted to plot 1 million observations and produce the > command > > plot(rnorm(1000000)) > > The labels of the xaxis are 0, e+00 2 e+05 etc. These are clearly not > very > attractive (The plots are for a PhD. thesis). > > I would like the axes to be 0,2,4,6,8,10 with a *10^5 on the right > hand > side. > > Is there a simple command for this? > > Best Wishes > > Roger See ?plotmath for some additional examples and there are some others in the list archives.  set.seed(1)  x <- rnorm(1000000)  # Now do the plot, but leave the x axis blank  plot(x, xaxt = "n")  # Set the x axis label tick marks  x.at <- seq(0, 10, 2) * 10 ^ 5  # Create the expressions for the tick mark labels  # Using parse() takes the character vectors from paste()  # and converts them to expressions for use in plotmath  x.lab <- parse(text = paste(seq(0, 10, 2), "%*% 10^5"))  # Now do the axis labels  axis(1, at = x.at, labels = x.lab) HTH, Marc Schwartz ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Axis/Ticks/Scale

 >>>>> "Marc" == Marc Schwartz (via MN) <[hidden email]> >>>>>     on Wed, 28 Dec 2005 15:46:37 -0600 writes:     Marc> On Wed, 2005-12-28 at 20:15 +0000,     Marc> [hidden email] wrote:     >> Dear All,     >>     >> Apologies for this simple question and thanks in advance     >> for any help given.     >>     >> Suppose I wanted to plot 1 million observations and     >> produce the command     >>     >> plot(rnorm(1000000))     >>     >> The labels of the xaxis are 0, e+00 2 e+05 etc. These are     >> clearly not very attractive (The plots are for a     >> PhD. thesis).     >>     >> I would like the axes to be 0,2,4,6,8,10 with a *10^5 on     >> the right hand side.     >>     >> Is there a simple command for this?     >>     >> Best Wishes     >>     >> Roger     Marc> See ?plotmath for some additional examples and there     Marc> are some others in the list archives. Yes, I think this one is there too: It has the "* 10^k" after each number; the nice thing about it is that it works for all kind of data -- and of course, in principle it could be built into R ... ###----------------- Do "a 10^k" labeling instead of "a e" --- axTexpr <- function(side, at = axTicks(side, axp=axp, usr=usr, log=log),                     axp = NULL, usr = NULL, log = NULL) {     ## Purpose: Do "a 10^k" labeling instead of "a e"     ##      this auxiliary should return 'at' and 'label' (expression)     ## ----------------------------------------------------------------------     ## Arguments: as for axTicks()     ## ----------------------------------------------------------------------     ## Author: Martin Maechler, Date:  7 May 2004, 18:01     eT <- floor(log10(abs(at)))# at == 0 case is dealt with below     mT <- at / 10^eT     ss <- lapply(seq(along = at),                  function(i) if(at[i] == 0) quote(0) else                  substitute(A %*% 10^E, list(A=mT[i], E=eT[i])))     do.call("expression", ss) } x <- 1e7*(-10:50) y <- dnorm(x, m=10e7, s=20e7) plot(x,y) ## ^^^^^^ not so nice; ok, try par(mar=.1+c(5,5,4,1))## << For the horizontal y-axis labels, need more space plot(x,y, axes= FALSE, frame=TRUE) aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX)) if(FALSE) # rather the next one { aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY))} ## or rather (horizontal labels on y-axis): aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY), las=2) ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Axis/Ticks/Scale

 On Thu, 2005-12-29 at 22:06 +0100, Martin Maechler wrote: > >>>>> "Marc" == Marc Schwartz (via MN) <[hidden email]> > >>>>>     on Wed, 28 Dec 2005 15:46:37 -0600 writes: > >     Marc> On Wed, 2005-12-28 at 20:15 +0000, >     Marc> [hidden email] wrote: >     >> Dear All, >     >> >     >> Apologies for this simple question and thanks in advance >     >> for any help given. >     >> >     >> Suppose I wanted to plot 1 million observations and >     >> produce the command >     >> >     >> plot(rnorm(1000000)) >     >> >     >> The labels of the xaxis are 0, e+00 2 e+05 etc. These are >     >> clearly not very attractive (The plots are for a >     >> PhD. thesis). >     >> >     >> I would like the axes to be 0,2,4,6,8,10 with a *10^5 on >     >> the right hand side. >     >> >     >> Is there a simple command for this? >     >> >     >> Best Wishes >     >> >     >> Roger > > >     Marc> See ?plotmath for some additional examples and there >     Marc> are some others in the list archives. > > Yes, I think this one is there too: > It has the "* 10^k" after each number; > the nice thing about it is that it works for all kind of data > -- and of course, in principle it could be built into R ... > > > > ###----------------- Do "a 10^k" labeling instead of "a e" --- > > axTexpr <- function(side, at = axTicks(side, axp=axp, usr=usr, log=log), >                     axp = NULL, usr = NULL, log = NULL) > { >     ## Purpose: Do "a 10^k" labeling instead of "a e" >     ##      this auxiliary should return 'at' and 'label' (expression) >     ## ---------------------------------------------------------------------- >     ## Arguments: as for axTicks() >     ## ---------------------------------------------------------------------- >     ## Author: Martin Maechler, Date:  7 May 2004, 18:01 >     eT <- floor(log10(abs(at)))# at == 0 case is dealt with below >     mT <- at / 10^eT >     ss <- lapply(seq(along = at), >                  function(i) if(at[i] == 0) quote(0) else >                  substitute(A %*% 10^E, list(A=mT[i], E=eT[i]))) >     do.call("expression", ss) > } > > > x <- 1e7*(-10:50) > y <- dnorm(x, m=10e7, s=20e7) > plot(x,y) > ## ^^^^^^ not so nice; ok, try > > par(mar=.1+c(5,5,4,1))## << For the horizontal y-axis labels, need more space > plot(x,y, axes= FALSE, frame=TRUE) > aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX)) > if(FALSE) # rather the next one > { aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY))} > ## or rather (horizontal labels on y-axis): > aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY), las=2) Nice Martin! I do like that.  I also like the handling of zero, which I realized after sending my reply, thus should have used:   x <- rnorm(1000000)   plot(x, xaxt = "n")   x.at <- seq(0, 10, 2) * 10 ^ 5   # Handle the zero here this time   x.lab <- parse(text = paste(seq(2, 10, 2), "%*% 10^5"))   axis(1, at = x.at, labels = c(0, x.lab)) BTW, on your approach, it was here:   http://finzi.psych.upenn.edu/R/Rhelp02a/archive/36462.htmland more recently, here:   http://finzi.psych.upenn.edu/R/Rhelp02a/archive/57011.html:-) Best regards and Happy New Year, Marc ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Axis/Ticks/Scale

 In reply to this post by Martin Maechler [hidden email] wrote: > ... > I would like the axes to be 0,2,4,6,8,10 with a *10^5 on > the right hand side. >   > Is there a simple command for this? This post so interested me that I wrote the following function: axis.mult<-function(side=1,at=NULL,labels,mult=1,mult.label,mult.line,   mult.labelpos=NULL,...) {   if(is.null(at)) at<-axTicks(side)   if(missing(labels)) labels<-at/mult   axis(side,at,labels,...)   if(missing(mult.label)) mult.label<-paste("x",mult,collapse="")   # multiplier position defaults to centered on the outside   if(is.null(mult.labelpos)) mult.labelpos<-side   edges<-par("usr")   if(side %% 2) {    # either top or bottom    if(mult.labelpos %% 2) {     adj<-0.5     at<-(edges[1]+edges[2])/2     if(missing(mult.line)) mult.line<-ifelse(mult.labelpos == side,3,0)    }    else {     adj<-ifelse(mult.labelpos == 2,1,0)     at<-ifelse(mult.labelpos == 2,edges[1],edges[2])     if(missing(mult.line)) mult.line<-1    }   }   else {    # either left or right    if(mult.labelpos %% 2) {     adj<-ifelse(mult.labelpos == 1,1,0)     at<-ifelse(mult.labelpos == 1,edges[3],edges[4])     if(missing(mult.line)) mult.line<-1    }    else {     adj<-0.5     at<-(edges[3]+edges[4])/2     if(missing(mult.line)) mult.line=ifelse(mult.labelpos == side,3,0)    }   }   mtext(mult.label,side,mult.line,at=at,adj=adj) } which will be in the next (v2.0.1) version of plotrix. Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## A difficulty with boot package

 Hi,       I have a difficulty with the bootstrap procedure in boot package. How can I specify the size of sample at each bootstrap ?   I use         >myboot<-boot(data,boot.fun,R=300)   when I display myboot\$t I get a vector with just one value the than the compute statistic in my data file after reading about bootstrap in the book MASS I add        >set.seed(101)   But I get the same result. than mean than at each boot the sample draw is exactly the data file. How can I do resolve this ?       Sincerly !                 ---------------------------------         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate