When we create a plot in R, the Y-axis labels are automatically generated and if we want to remove those labels, the plot function can help us. For this purpose, we need to set ylab argument of plot function to blank as ylab="" and yaxt="n" to remove the axis title.
Example 1: Disable Scientific Notation of ggplot2 Axis We did that by applying the scale_x_continuous function in combination with the comma function of the scales package.
If you are going to create a custom axis, you should suppress the axis automatically generated by your high level plotting function. The option axes=FALSE suppresses both x and y axes. xaxt="n" and yaxt="n" suppress the x and y axis respectively.
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)
Did you try something like :
options(scipen=10000)
before plotting ?
Just an update to what @Arun made, since I tried it today and it didn't work because it was actualized to
+ scale_x_continuous(labels = scales::comma)
As a more general solution, you can use scales::format_format
to remove the scientific notation. This also gives you lots of control around how exactly you want your labels to be displayed, as opposed to scales::comma
which only does comma separations of the orders of magnitude.
For example:
require(ggplot2)
require(scales)
df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))
# Here we define spaces as the big separator
point <- format_format(big.mark = " ", decimal.mark = ",", scientific = FALSE)
# Plot it
p <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
p + scale_x_continuous(labels = point)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With