Maybe I have missed this in the stackexchange literature, as I'm surprised to find many solutions for adding floating axis labels and adjustments to axes (e.g. add "floating" axis labels in facet_wrap plot), but nothing to solve my issue of overlapping x-axis labels with a facet_wrap and scales = "free". This one is close, but for an older ggplot version: overlapping y-scales in facet (scale="free"). This one may be the answer, to write a function to do such an operation, but I couldn't make it work for me: Is there a way of manipulating ggplot scale breaks and labels?
Here is a reproducible example:
v<-runif(1000,min=1000000,max=10000000)
x<-runif(100,min=0.1,max=1)
y<-runif(100000,min=0,max=20000)
z<-runif(100000,min=10000,max=2000000)
df<-data.frame(v,x,y,z)
colnames(df)<-c("Order V","Order X","Order Y","Order z")
library(reshape2)
melt.df<-melt(df[,c(1:4)])
library(ggplot2)
ggplot(melt.df, aes(x = value)) +
geom_histogram(bins=50,na.rm=TRUE) +
facet_wrap(~variable, scales="free") +
theme_bw()
The resulting figure is this:
I have a similar setup, which produces this:
Any help on a cmd to do this, or a function that could set up these x-axis label breaks would be awesome!
diamond
example has 2 digits in every x-axis label and the other plot has between 4 and 7 digits for each label. It seems like thediamond
example isn't a good one. – Gregor Thomas