Force R to Stop Plotting Abbreviated Axis Labels (Scientific Notation) - E.G. 1E+00

Force R to stop plotting abbreviated axis labels (scientific notation) - e.g. 1e+00

I think you are looking for this:

require(ggplot2)
df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))
# displays x-axis in scientific notation
p <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
p

# displays as you require
require(scales)
p + scale_x_continuous(labels = comma)

avoid scientific notation x axis ggplot

You can use options(scipen = 999) before you plot.

This will disable scientific notation in general and not only in your x-axis.

avoid scientific notation x axis ggplot

You can use options(scipen = 999) before you plot.

This will disable scientific notation in general and not only in your x-axis.

How do I change the formatting of numbers on an axis with ggplot?

I also found another way of doing this that gives proper 'x10(superscript)5' notation on the axes. I'm posting it here in the hope it might be useful to some. I got the code from here so I claim no credit for it, that rightly goes to Brian Diggs.

fancy_scientific <- function(l) {
# turn in to character string in scientific notation
l <- format(l, scientific = TRUE)
# quote the part before the exponent to keep all the digits
l <- gsub("^(.*)e", "'\\1'e", l)
# turn the 'e+' into plotmath format
l <- gsub("e", "%*%10^", l)
# return this as an expression
parse(text=l)
}

Which you can then use as

ggplot(data=df, aes(x=x, y=y)) +
geom_point() +
scale_y_continuous(labels=fancy_scientific)

Forcing a 1e3 instead of 1000 format in ggplot R

You can use the breaks and labels parameters of scale_y_log10 as in

library(ggplot2)

ggplot(data=subset(movies, votes > 1000)) +
aes(x = rating, y = votes / 10000) +
scale_y_log10(breaks = c(0.1, 1, 10), labels = expression(10^-1, 10^0, 10^1)) +
geom_point()

This might not be an elegant solution, but it works if you only have a limited number of plots.

Number formatting axis labels in ggplot2?

One needs to load library(scales) before attempting this.

ggplot2, getting a % symbol in subscript within axis labels

Moving the % sign in the square brackets and using quotation marks"" removes the error message

iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) + 
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah["1d%"]))

and yields this plot:

Sample Image



Related Topics



Leave a reply



Submit