[R] How to create a legend without plot, and to use scientific notation for axes label ?

Hans-Joerg Bibiko bibiko at eva.mpg.de
Thu Apr 10 13:07:52 CEST 2008


On 10 Apr 2008, at 12:57, Hans-Joerg Bibiko wrote:
>
> On 10 Apr 2008, at 12:33, Stanley Ng wrote:
>> How can I use formatC to convert 6000000 to 6e5 and not 6e+05 ?
>>
>>> formatC(600000)
>> [1] "6e+05"
>>> formatC(600000, format="e", digit=0)
>> [1] "6e+05"
>
>
> Try this:
>
> gsub("([eE])(\\+?)(\\-?)0+", "\\1\\3", formatC(600000, format="e",
> digit=0))

Sorry this only works up to e+09 or e-09.

This should handle all:

gsub("([eE])(\\+?)(\\-?)0*", "\\1\\3", formatC(600000, format="e",  
digit=0))


--Hans



More information about the R-help mailing list