Skip to content

Show date on graph

4 messages · Syed Abid Hussaini, Uwe Ligges, Jim Lemon

#
I have a character "2006-11-06" which was originally scanned from a csv file. This character is
named date. I now use mtext (date) on a plot and i see strange cluttered characters instead of
2006-11-06. I tried many ways but i dont know whats going on. Then for testing i made an
artificial character d <- ("2006-11-06") and now when i do mtext (d) it shows up on the plot.
While both date and d return "2006-11-06" only d shows up on the plots. Any help would be appreciated.


 
____________________________________________________________________________________
Have a burning question?  
Go to www.Answers.yahoo.com and get answers from real people who know.
#
Syed Abid Hussaini wrote:
Then it is not a character but some date/time object such as a POSIXlt 
class. mtext() does not have an appropriate method for it. If this date 
is x, just plot as.character(x) instead.

Uwe Ligges
#
Syed Abid Hussaini wrote:
Hi Syed,
If you try to display something with mtext, it expects the object to be 
a character string. When you just print the object, the print method 
works out that it is a date object and silently converts it to a 
character string to be printed. Try this:

mtext(format(date,"%Y-%m-%d"),...)

Also note that it isn't a great idea to use "date" to name a variable. 
Even though you can now get away with it, using the same name for two 
things (a function and a variable) often comes back to haunt one.

Jim
#
Thanks Jim and Uwe!!

  Both methods work for me. 

Methods:

1. plot as.character(x) 

2. mtext(format(date,"%Y-%m-%d"),...)