Coder Social home page Coder Social logo

Comments (13)

daattali avatar daattali commented on May 31, 2024

Thanks for the report. Fixing

from ggextra.

WilDoane avatar WilDoane commented on May 31, 2024

A version of this problem appears to still exist when geom_smooth() extends the axis range.

gg <-
    ggplot(mtcars, aes(x = mpg, y = cyl)) + 
    geom_point() 
ggMarginal(gg, type = "histogram")

mtcars2

gg <-
    ggplot(mtcars, aes(x = mpg, y = cyl)) + 
    geom_point() +
    geom_smooth()
ggMarginal(gg, type = "histogram")

mtcars

package       * version date       source        
 colorspace      1.2-6   2015-03-11 CRAN (R 3.2.2)
 devtools        1.10.0  2016-01-23 CRAN (R 3.2.3)
 digest          0.6.9   2016-01-08 CRAN (R 3.2.3)
 ggExtra       * 0.3.1   2015-11-07 CRAN (R 3.2.3)
 ggplot2       * 2.1.0   2016-03-01 CRAN (R 3.2.3)
 gridExtra       2.2.1   2016-02-29 CRAN (R 3.2.3)
 gtable          0.2.0   2016-02-26 CRAN (R 3.2.3)
 labeling        0.3     2014-08-23 CRAN (R 3.2.2)
 memoise         1.0.0   2016-01-29 CRAN (R 3.2.3)
 munsell         0.4.3   2016-02-13 CRAN (R 3.2.3)
 plyr            1.8.3   2015-06-12 CRAN (R 3.2.2)
 Rcpp            0.12.3  2016-01-10 CRAN (R 3.2.3)
 RevoUtilsMath * 3.2.3   2016-02-09 local         
 scales          0.4.0   2016-02-26 CRAN (R 3.2.3)

from ggextra.

daattali avatar daattali commented on May 31, 2024

Thanks for the report. I'm really busy for the next 2 months, I'll try to take a look when I can, but unfortunately this is low priority at the moment

from ggextra.

daattali avatar daattali commented on May 31, 2024

@WilDoane I looked into this a bit but wasn't able to find a good solution. What I tried to do is to just copy the scale aesthestics from the main plot to the marginal plot, but for some reason it doesn't work. If anyone wants to tackle this, I'd gladly welcome a PR.

from ggextra.

maelle avatar maelle commented on May 31, 2024

@daattali "What I tried to do is to just copy the scale aesthestics from the main plot" -> where exactly in ggMarginal? Do you mean

        ggplot2::scale_x_continuous(breaks = mean(getLimits(pbTop, "x")),
                                    labels = ylabel)

?

I'm looking at the problem because a colleague of mine uses custom x and y limits.

from ggextra.

daattali avatar daattali commented on May 31, 2024

@masalmon getLimits() and getScale() are two functions I use to try to match the original plot. If your colleague uses custom x and y limits, she should be fine, that works. Example:

ggExtra::ggMarginal(
  ggplot(mtcars, aes(mpg,wt)) +
    geom_point() + 
    scale_x_continuous(limits = c(-5, 60))
)

What doesn't work is using geom_smooth() - then the y-axis marginal plot is a bit out of place

from ggextra.

jimoeppen avatar jimoeppen commented on May 31, 2024

The original issue raised by zakahmad in 2015 still seems to be present, without using geom_smooth. If the default axis limits are over-ridden, the x-axis marginal plot aligns correctly with the data, but the y-axis marginal plot does not. Here is some code to illustrate the situation [R 3.4.3; ggExtra_0.7; ggplot2_2.2.1]:

df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50))
p1 <- ggplot2::ggplot(df, ggplot2::aes(x, y)) + ggplot2::geom_point() +
scale_x_continuous(limits = c(0, 150)) +
scale_y_continuous(limits = c(0, 100))
ggMarginal(p1, type = "histogram")

from ggextra.

crew102 avatar crew102 commented on May 31, 2024

@jimoeppen , the problem with using limits with ggMarginal that you mention is related to #81.

from ggextra.

jimoeppen avatar jimoeppen commented on May 31, 2024

from ggextra.

crew102 avatar crew102 commented on May 31, 2024

Hi @jimoeppen, both axis are actually problematic. You can see both graphs in #81 for this, or just check out the below code, in which the x marginal plot is wrong and we don't even get a y marginal plot.

library(ggplot2)
library(ggExtra)

p <- ggplot(data = mtcars) +
  geom_point(aes(wt, mpg)) +
  ylim(c(25, 35))

ggMarginal(p, type = "histogram")

The bigger issue mentioned in #81 is that ggMarginal is not using the correct range for the marginal plots.

from ggextra.

jessiepluto avatar jessiepluto commented on May 31, 2024

I just encountered this same issue -- ggMariginal histograms are not lining up with the y-axis correctly after adjusting the limits. Is there any update on a solution?

from ggextra.

daattali avatar daattali commented on May 31, 2024

A huge feature was just added, the fix for this is next

from ggextra.

daattali avatar daattali commented on May 31, 2024

fixed

from ggextra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.