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:
Related Topics
Create and Assign Multiple New Dataframe Columns in Ifelse Statement
R: Error in Usemethod("Group_By_"):Applied to an Object of Class
Pass a String as Variable Name in Dplyr::Filter
Use Dynamic Name For New Column/Variable in 'Dplyr'
Summarizing Multiple Columns With Dplyr
How to Use R'S Ellipsis Feature When Writing Your Own Function
Predict() - Maybe I'M Not Understanding It
How to Change Legend Title in Ggplot
How to Plot All the Columns of a Data Frame in R
How to Add a Suffix (Or Prefix) Elements of an Existing List
How to Select Variables in an R Dataframe Whose Names Contain a Particular String
Rstudio Does Not Display Any Output in Console After Entering Code
Installing Rgl on Ubuntu and Mac: X11 Not Found
Drop Unused Factor Levels in a Subsetted Data Frame
Unique Combination of All Elements from Two (Or More) Vectors
Show Percent % Instead of Counts in Charts of Categorical Variables