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 Answers.yahoo.com and get answers from real people who know.
Syed Abid Hussaini wrote:> 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 ofThen 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> 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 Answers.yahoo.com and get answers from real people who know. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Syed Abid Hussaini wrote:> 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. > > >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