Is it possible to control formatting of the numbers which go along the axes in plots? e.g. plot(x=1:1000000,y=1:1000000) will label the X axis as "0d+00", "2e+05" &c. I want that to read 0, 200k, 400k &c. I know of the function axis(), but it offers far too much control for this simple task. thanks. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://www.memritv.org http://jihadwatch.org http://pmw.org.il http://americancensorship.org http://think-israel.org Why do we want intelligent terminals when there are so many stupid users?
It is possible, but only by using axis() since you can specify axis breaks in a plot command, but not the labels. You can ignore most of the axis() options so the commands are pretty simple: plot(x=c(1, 1000000), y=c(1, 1000000), xlab="x", ylab="y", xaxt="n", yaxt="n", las=2) pos <- c(0, 200000, 400000, 600000, 800000, 1000000) lbl <- c("0", "200k", "400k", "600k", "800k", "1000k") axis(1, pos, lbl) axis(2, pos, lbl) # or axis(2, pos, lbl, las=2) to rotate the y tick mark labels. ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Sam Steingold > Sent: Thursday, December 20, 2012 1:22 PM > To: r-help at r-project.org > Subject: [R] axes labeling > > Is it possible to control formatting of the numbers which go along the > axes in plots? > e.g. > plot(x=1:1000000,y=1:1000000) > will label the X axis as "0d+00", "2e+05" &c. > I want that to read 0, 200k, 400k &c. > I know of the function axis(), but it offers far too much control for > this simple task. > thanks. > -- > Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X > 11.0.11103000 > http://www.childpsy.net/ http://www.memritv.org http://jihadwatch.org > http://pmw.org.il http://americancensorship.org http://think-israel.org > Why do we want intelligent terminals when there are so many stupid > users? > > ______________________________________________ > 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.
By "too much control" do you mean that axis requires too many inputs? You can use axTicks to get the positions of the tick marks that would have been drawn and create labels based on those positions. E.g.,> myAxis <- function (side) {at <- axTicks(side = side) lab <- ifelse(abs(at)>=1e6, paste(at/1e6, "M"), paste0(at/1e3, "k")) # alter to suit your tastes axis(side = side, at = at, lab = lab) }> plot(c(1,1200), c(1,1e6), axes=FALSE) > myAxis(side=1) # "0k", "0.2k", ..., "1.2k" on x axis > myAxis(side=2) # "0k", ..., "800k", "1M" on y axisBill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Sam Steingold > Sent: Thursday, December 20, 2012 11:22 AM > To: r-help at r-project.org > Subject: [R] axes labeling > > Is it possible to control formatting of the numbers which go along the > axes in plots? > e.g. > plot(x=1:1000000,y=1:1000000) > will label the X axis as "0d+00", "2e+05" &c. > I want that to read 0, 200k, 400k &c. > I know of the function axis(), but it offers far too much control for > this simple task. > thanks. > -- > Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 > http://www.childpsy.net/ http://www.memritv.org http://jihadwatch.org > http://pmw.org.il http://americancensorship.org http://think-israel.org > Why do we want intelligent terminals when there are so many stupid users? > > ______________________________________________ > 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.