0

Is there a way to use coord_cartesian to set the lower y limit to 0, but continue the automatic setting for ymax?

I have a large set with multiple groups and categories. I want them each group to display on it's own page with facets for every category, so I am content with the automatic upper-bounds.

I am making qq plots, and because of skewed data, the normal distribution (from stat_qq_line) goes into the negative. Simply setting ymin would limit stat_qq_line, so I want to use coord_cartesian instead.

I was hoping

coord_cartesian(ylim = c(0, NA))

would work, but it produces

Error in if (zero_range(range)) zero_width else diff(range) : 
  missing value where TRUE/FALSE needed

Entire block if that helps:

p <- ggplot(dsub2, mapping = aes(sample = Usual)) +
stat_qq_line() + stat_qq_point() +
facet_wrap(~Category, scales = "free", labeller=labeller(Category = labels)) +
labs(title=paste("Group", group),
x = "Theoretical Quantiles", y = "Sample Quantiles") +
theme(plot.title = element_text(hjust = 0.5)) + 
coord_cartesian(ylim = c(0, NA))
  • Have you tried the standard `+ expand_limits(y = 0)`? [See this question for an example](https://stackoverflow.com/q/13701347/903061). My guess is it will still work with a `coord` function but I'm not 100% sure. If you have tried that, and it still doesn't work, can you share a small reproducible sample of data? – Gregor Thomas Apr 26 '19 at 16:50
  • It looks like someone came up with a possible work-around for `NA` limits in `coords` in [this open GitHub issue](https://github.com/tidyverse/ggplot2/issues/2907) that you could try. – aosmith Apr 26 '19 at 16:52
  • @gregor I was unfamiliar with that, but for some reason adding that does not change anything except it adds the warning message: In pushvpgp(x) : reached elapsed time limit. Going to try reproducing this with one of the default r libraries and see if that helps. Not sure how else to get a sample of my data on here. – marmaluffalo Apr 26 '19 at 17:23
  • 2
    `dput()` is a nice way to share a reproducible sample of data, e.g., `dput(droplevels(your_data[1:10, ]))` for the first 10 rows. Or you can share code to simulate some sample data. Or use a built-in dataset. Do note that we certainly don't need your whole "large set with multiple groups and exercises", just enough data to illustrate the problem. [Here's a FAQ about creating reproducible examples in R](https://stackoverflow.com/q/5963269/903061), it has lots more suggestions. – Gregor Thomas Apr 26 '19 at 17:30

0 Answers0