Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marginal plots don't reflect axis limits made using coordinate system (e.g., coord_cartesian()) #128

Open
crew102 opened this issue Aug 15, 2018 · 11 comments

Comments

@crew102
Copy link
Contributor

crew102 commented Aug 15, 2018

As mentioned by @Futats in #75

library(ggplot2)
library(ggExtra)

p <- ggplot(mtcars) +
  geom_point(aes(wt, drat)) +
  coord_cartesian(xlim = c(4, 5.5))

ggMarginal(p)

Created on 2018-08-15 by the reprex package (v0.2.0).

@crew102
Copy link
Contributor Author

crew102 commented Sep 29, 2018

Turns out this is a really hairy issue. I think it can be fixed, but it leads to some very confusing code, so much so that I'm not sure it's worth it to fix.

@DoaneAS
Copy link

DoaneAS commented Jun 3, 2019

Axis limits are basic plot attributes. Is there any way to specify axis limits for the marginal plots?

@crew102
Copy link
Contributor Author

crew102 commented Jun 3, 2019

Do you mean you want to set the limits of the marginal plots to be different from the limits used in the scatter plot?

@DoaneAS
Copy link

DoaneAS commented Jun 4, 2019

I want the limits to be the same in the scatter and box plots. I’m setting scatter plot limits with coord_cartesian(xlim = xlim, ylim = ylim), but the box plots are not picking this up.

@crew102
Copy link
Contributor Author

crew102 commented Jun 4, 2019

Try using xlim/ylim or scale_x_continuous/scale_y_continuous:

library(ggplot2)
library(ggExtra)

p <- ggplot(mtcars) +
  geom_point(aes(wt, drat)) +
  xlim(c(4, 5.5))

ggMarginal(p)
#> Warning: Removed 28 rows containing missing values (geom_point).

Created on 2019-06-03 by the reprex package (v0.2.0.9000).

@piaebe
Copy link

piaebe commented Oct 29, 2019

Using xlim/ylim or scale_x_continuous work so that the marginal plots adapt to the same axis, which works welll for scatterplots but not for additional line plots as they are cut at the limits even if the shown axis extends a bit further.
Therefore, I would like to use coord_cartesian or alternatively scale_x_continuous(limits=limits, expand=c(0,0)). I want to plot a scatterplot together with a geom_line() without cutting any data AND with marginal boxplots using the same axis range.
Is there any solution for this issue already?

@crew102
Copy link
Contributor Author

crew102 commented Oct 30, 2019

Hmm, my first thought is probably not, there won't be a way to do that b/c it will require coord_cartesian. If you can provide an example of the type of behavior that you're seeing and what you would prefer to see, I can take a closer look at it.

@piaebe
Copy link

piaebe commented Nov 1, 2019

Thank you for considering my request!
Aim: a scatterplot together with boxplot margins, a line plot and defined axis limits, because I have several subplots and want to use the same limits.
Problem: either no limits, cut line plot or boxplots not matching data points
Example code:

line <- data.frame("wt"=0:10,"drat"=0:10)

p <- ggplot(data=mtcars, aes(wt, drat)) +
  geom_point() +
  geom_line(data=line)

limits <- c(1, 6)

ggMarginal(p, type="boxplot") # boxplots match, but no limits defined

ggMarginal_p

p1 <- p + coord_cartesian(limits)
ggMarginal(p1, type="boxplot") # boxplot does not adapt to coord_cartesian

ggMarginal_p1

p2 <- p + xlim(limits)
ggMarginal(p2, type="boxplot") # line stops before end of plot window, boxplot good

ggMarginal_p2

p3 <- p + scale_x_continuous(limits=limits, expand=c(0,0))
ggMarginal(p3, type="boxplot") # boxplot does not adapt to expand, line ok (but actually only if line data points matches with limits)

ggMarginal_p3

@crew102
Copy link
Contributor Author

crew102 commented Nov 2, 2019

Hi @pricklpitty , thanks for clarifying/for the good examples. Unfortunately what you want to do would require a fix to how ggMarginal deals with the the "cartesian" coordinate system (i.e., a fix to the issue originally reported here), which isn't easy. We've decided not to attempt to fix this issue for now, as it would introduce quite a bit of complexity into the code.

@piaebe
Copy link

piaebe commented Nov 8, 2019

Hi @crew102, thank you for your response. Yes, it would require to fix the original issue posted here. Unfortunately, I am still struggling with this issue, e.g. trying to use dummy data to fix the limits, but I do not succeed in matching boxplots AND continue the line to figure limits, I can only produce one of the targets at once... Do you have any workaround suggestion for me?

@crew102
Copy link
Contributor Author

crew102 commented Nov 14, 2019

Hmm, yeah, sorry, I can't think of one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants