I am not very proficient in R, and I have stumbled upon an obstacle when using ggplot2. I have a plot with large numbers on both the x and y axis of the plot. Since I am dealing with large numbers, ggplot2's default behavior is to label the ticks using "scientific" notation (such as 1e+05, 2e+05, etc.). I would like the tick labels on either axis to be written in "exponential" notation (such as 105, 2·105, etc.). In other words, I would simply like to have the default scientific labels and breaks chosen by ggplot2 rewritten into the exponential notation. I appreciate the suggestions that I have found elsewhere on this site, which offer some solutions for avoiding scientific notation, but to avoid clutter, I specifically ...
- do not want to log-rescale the axis with something like:
scale_x_log10(limits = c(1, 1e7),
breaks = breaks_log(n=8, base = 10),
labels = label_log((base = 10))
- do not want to have large numbers written in non-exponential form, which can be achieved with something like this:
scale_x_log10(labels = function(x) format(x, scientific = FALSE))
- do not want to use suffixes K, M, G or the like to represent thousands, millions, billions, etc.
The closest thing I have found is posted here: How can I format axis labels with exponents with ggplot2 and scales? by sherifffruitfly. He suggests the following:
scale_y_continuous(label= function(x) {ifelse(x==0, "0", parse(text=gsub("[+]", "", gsub("e", " %*% 10^", scientific_format()(x)))))})
Which is almost what I would want since it gives the numbers in the format 2 x 105, but the labels(numbers) are not horizontally justified, and they do contain an 'x', instead of the '·' between the coefficient and the power of ten. Is there a simple function, for example in scales package, that does what I want? It would also be neat if the solution works with negative numbers with large absolute value, as well as numbers between <-1, 1>, such as -2·105, etc. Thanks everyone for reading, and my apologies if I missed something very obvious.