2
votes

I want to show big numbers in a plot in r. but I get this error:

my numbers are:

[1] "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11"
[8] "9,02E+11" "9,02E+11" "9,02E+11" "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12"
[15] "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12" "1,31E+13"
[22] "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13"
[29] "1,31E+13" "1,31E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13"
[36] "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,36E+13" "1,36E+13"
[43] "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13"
[50] "1,36E+13" "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12"
[57] "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12" "2,64E+12" "2,64E+12" "2,64E+12"
[64] "2,64E+12"

and the simple code:

plot(dataliste,type="l")

I am reading thi svalues from an excell file and I cant specify a limit for ylim, becuase they are in a wide range. What should I do to solve this problem

1
What's the error? What class are your "numbers"? I'm guessing either factor or character, right? Give us the result of str(dataliste). - Roman Luštrik
the result of this command is: chr [1:64] "9,02E+11" "9,02E+11" "9,02E+11"... and the error is what I have written as subject need finite 'ylim' values - Kaja

1 Answers

6
votes

Try this:

plot(sapply(dataliste, function(x)gsub(",", ".", x)))

As Roman Luštrik pointed out, you most likely have characters in your data. You can generally plot them or convert them with as.numeric. However, since you have a , instead of a . in your strings, the conversion to numeric fails. Example:

> as.numeric("9,02E+11")
[1] NA
Warning message:
NAs introduced by coercion 
> as.numeric("9.02E+11")
[1] 9.02e+11

With gsub, as above, you can substitute the , for a . for each number and plotting should work.