Skip to content

Axes value format

9 messages · Vihan Pandey, John Kane, David Winsemius +1 more

#
Hi all,

I have some graphs where the values on the X and Y axes are by default
in exponent form like 2e+05 or 1.0e+07. Is it possible to make them in
a more readable form like 10M for 1.0e+07 or 200K for 2e+05?

Thanks and Regards,

- vihan
#
Quite likely, but we need to know what you are doing and what graphics package you are using.

PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

John Kane
Kingston ON Canada
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
#
On 8 May 2012 19:47, John Kane <jrkrideau at inbox.com> wrote:
Frightfully sorry about that. I'm using R on a Mac, and its a simple
plot using plot() which is taking values from a CSV file, let me
illustrate for one dataset :

======
#!/usr/bin/Rscript

out_file = "foobar.pdf"
pdf(out_file, height=8.5, width=11)

my_values <- read.csv("foo.csv",head=TRUE,sep=",")

plot(my_values$num_sims,
	my_values$exec_time,
	xlab="Number of Simulations",
	ylab="Execution Time(in milliseconds)",
	col="red",
	main="Execution Time for Simulations")

lines(my_values$num_sims,my_values$exec_time,col="red")

my_values2 <- read.csv("bar.csv",head=TRUE,sep=",")

lines(my_values2$num_sims,my_values2$exec_time,col="blue")
points(my_values2$num_sims,my_values2$exec_time,col="blue")


legend("topright",
	lty=c(1,1),
	  c("foo","bar"),
	  col=c("red","blue")
	  );

dev.off()

print(paste("Plot was saved in:", getwd()))
======

foo.csv and bar.csv have values like:

"num_sims","exec_time"
1000000,44556
2000000,89112
3000000,133668

etc.

Please let me know if you require any additional information.

Cheers!

- vihan
#
On May 8, 2012, at 2:23 PM, Vihan Pandey wrote:

            
See if this is helpful. Untested,  since you still do not have a  
reproducible example for us to work with.

x <- c(12345, 1234567, 123)
paste( round( x/c(1, 1000, 1000000)[findInterval(x,  
c(1,1000,1000000)) ], 2),
         c("","K","M")[findInterval(x, c(1,1000,1000000)) ]  )

[1] "12.35 K" "1.23 M" "123 "
#
Actually I meant a working example and some data (See ?dput for a handy way to supply data)

It is also a good idea to include the information from sessionInfo()


 I think David W has a good approach.  

Otherwise you might just want to write the axis yourself.  

=============================
x  <- c(1000000, 2000000, 3000000)
y  <- c( 44556, 89112, 133668)

nms  <- c("1M", "2M", "3M")

plot(x,y, xaxt="n")
axis(1, x, labels=nms)
============================



John Kane
Kingston ON Canada
____________________________________________________________
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
#
Hi Vihan,

The link below might be helpful.


(http://stackoverflow.com/questions/3415097/controlling-number-formatting-at-axis-of-r-plots)

A.K.







----- Original Message -----
From: Vihan Pandey <vihanpandey at gmail.com>
To: r-help <r-help at r-project.org>
Cc: 
Sent: Tuesday, May 8, 2012 1:29 PM
Subject: [R] Axes value format

Hi all,

I have some graphs where the values on the X and Y axes are by default
in exponent form like 2e+05 or 1.0e+07. Is it possible to make them in
a more readable form like 10M for 1.0e+07 or 200K for 2e+05?

Thanks and Regards,

- vihan

______________________________________________
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.
1 day later
#
On 08/05/2012, David Winsemius <dwinsemius at comcast.net> wrote:
Thanks, xaxt, yaxt in plot() did the job. Sorry for not posting a
reproducible example I just needed a quick fix which I was sure would
be a simple option in plot() or elsewhere.

Thanks and Cheers!

- vihan
#
On 08/05/2012, John Kane <jrkrideau at inbox.com> wrote:
Sorry for not posting a working example and some data, I just wanted a
quick fix and didn't know people would work so much for my query few
mailing lists do so :-) Thanks though, your xaxt option did the trick.

I will learn from this and read up on dput and sessioninfo()

Thanks and Cheers!

- vihan
#
On 08/05/2012, arun <smartpink111 at yahoo.com> wrote:
Thanks, the xaxt parameter in plot() solved the problem.

Thanks and Cheers!

- vihan