I have a faceted ggplot
like so:
library(ggplot2)
grid <- seq(-10,10,length.out=1000)
df <- data.frame(x=rep(grid,2),y=c(grid^2,100+grid^2/100000000),group=rep(c(1,2),each=length(grid)))
ggplot(df,aes(x,y)) + geom_line() + facet_wrap(~group,scales='free')
Problem is that the y-axes values for group 2 are all identical because they only differ in the 6-7th decimal. So I tried
fmt <- function(){
function(x) format(x,nsmall = 7,scientific = FALSE)
}
ggplot(df,aes(x,y)) + geom_line() + facet_wrap(~group,scales='free') + scale_y_continuous(labels = fmt())
but that adds a lot of unnecessary decimals for the first group (duh!).
Is there any way to make ggplot
show however many decimal places are necessary for the values on the y-axis to all be different for all facets? Or is doing this manually with gridExtra
my best bet here?