3

There's a bunch of whitespace that R is automatically adding to my dot plot. Is there any way to to fix this (ie. by adjusting the y-scale)? Everything I've tried (adjusting ylim(), limits) doesn't change anything. Here is my code and I've attached a screenshot of the current plot.

ggplot(TieDomiData, aes(x = Science)) +
  geom_dotplot(binwidth = 1.5, stackratio = 1.5, 
               col = "olivedrab3",
               fill = "olivedrab3", 
               dotsize = 1) +
  scale_y_continuous(name = NULL, breaks = NULL) + 
  scale_x_continuous (
    name = "Mark",
    breaks = c(seq(40, 100, 5)),
    limits = c(40, 100),
    labels = c(seq(40, 100, 5)) 
  ) + 
  ggtitle("Grade 9 Overall Science Marks")

dot plot

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • 1
    See this thread: https://stackoverflow.com/questions/16216312/how-to-plot-stacked-point-histograms-in-ggplot2-in-r – user2363777 Mar 03 '19 at 00:22
  • 1
    I doubt R is adding whitespace: it is setting the scale based on the available size of the picture, and just puts in the number of dots it finds. If you had a less tall picture, the white space would reduce. If you had ten times as many points I suspect that the peak near 90 would break the top of the image – Henry Mar 03 '19 at 00:37
  • 1
    Having trouble implementing this / seeing how the above comments solve my problem. Could you please elaborate? –  Mar 03 '19 at 00:45
  • 1
    @TristanSharma: Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Mar 03 '19 at 01:25
  • I thjought there would have been an opportunity to use the `ylim()` function? – IRTFM Mar 03 '19 at 05:27

0 Answers0