ggplot
generally does a good job of creating sensible breaks and labels in scales.
However, I find that in plot with many facets and perhaps a formatter=
statement, the labels tend to get too "dense" and overprint, for example in this picture:
df <- data.frame(
fac=rep(LETTERS[1:10], 100),
x=rnorm(1000)
)
ggplot(df, aes(x=x)) +
geom_bar(binwidth=0.5) +
facet_grid(~fac) +
scale_x_continuous(formatter="percent")
I know that I can specify the breaks and labels of scales explicitly, by providing breaks=
and scale=
arguments to scale_x_continuous
.
However, I am processing survey data with many questions and a dozen crossbreaks, so need to find a way to do this automatically.
Is there a way of telling ggplot
to calculate breaks and labels automatically, but just have fewer, say at the minimum, maximum and zero point?
EDIT: Ideally, I don't want to specify the minimum and maximum points, but somehow tap into the built-in ggplot training of scales, and use the default calculated scale limits.
See Question&Answers more detail:os