Force R to write scientific notation as n.nn x 10 ^ -n with superscript

Say I have two floats

a <- 8.9384920e-24
b <- 0.00293892837

I would like to display any of them in a 10-basic scientific notation, rounded to two decimal places on the graph, possibly using paste(), but with superscript formatting after 10.

8.94 x 10^-24 #no ^ and superscript font
2.94 x 10^-4  #no ^ and supercript font, should be -4, not -04

This is really a maniac, but the boss asked him to, it must be done in the R database (and not ggplot2), or I will have to rewrite 600 lines of code ... Right now, all I see is that the floats print differently depending on how big they are ...

+3
source share
1 answer

You can check eaxisin packagesfsmisc

# some data
x <- seq(1, 100000, len = 10)
y <- seq(1e-5, 1e-4, len = 10)

# default axes
plot(x, y)

enter image description here

# eaxis
plot(x, y, axes = FALSE)
eaxis(side = 1)
eaxis(side = 2)

enter image description here

expression pretty10exp() . , :

plot(x, y, axes = FALSE)
title(pretty10exp(y[1]))

enter image description here

+6

Source: https://habr.com/ru/post/1583891/


All Articles