I am trying to use geom_dotplot. In general it works good for smaller datasets. But I'd also like to use it for larger amounts of data.
When running with default binwidth settings (so not specifying binwidth at all) some of the points will just be cut on the y-axis.
Take this a example code:
df <- data.frame(input = c(rep(3,100), runif(200)))
ggplot(data = df, aes(x = input)) +
geom_dotplot( binwidth = 0.015)
If I specify binwidth
this works perfectly and I can see all points in the plot.
But if I use just standard settings without specifying binwidth
like this:
ggplot(data = df, aes(x = input)) +
geom_dotplot( )
I get this plot:
Of course you could manually set binwidth each time. But I am looking for a solution, to automatically adjusts the binwidth (or some other parameter) in way that all points are displayed on the y-axis.
One of the problems is, that there is no reaction to commands like
ylim(0, 50)
or scale_y_continuous(limits=c(0, 2))
.
Probably related to this from the geom_dotplot
documentation
the numbers on y axis are not meaningful, due to technical limitations of ggplot2.
Was wondering if I maybe could use the "Computed variables" of geom_dotplot for this. Something like count. Like you usually do with geom_histogram with after_stat.
ggplot(mpg, aes(displ)) +
geom_histogram(aes(y = after_stat(count / max(count))))
But it seems it doesn't work as input for binwidth ... seems to only work inside of aes()...?
Maybe there is even a more obvious solution I didn't think of.