Coder Social home page Coder Social logo

Comments (7)

crew102 avatar crew102 commented on June 9, 2024 1

Can you provide a reproducible example of how you created that plot? To my knowledge, ggMarginal does not even have the ability to overlay marginal plots like the graph you displayed.

from ggextra.

SebastianoCurreli avatar SebastianoCurreli commented on June 9, 2024

Sure,
I'm not using the original dataset because it's quite big.
An example with some simulated data is as follows:

`set.seed(1234)
n = 500;
x1 = rbeta(n, .5, .4)
y1 = rnorm(n, 5, 2);
y2 = rnorm(n, 10, 1)
w = rbinom(n, 1, .5)
x2 = w*y1 + (1-w)*y2

df_ex1<-data.frame(x = x1, y = x2)
df_ex2<-data.frame(x = y1, y = y2)

p1 <- ggplot(df_ex1, aes(x, y)) + geom_point(color = "red") +
theme_cowplot() + xlim(0, 10) + ylim(0,15)

p2 <- ggplot(df_ex2, aes(x, y)) + geom_point(color = "blue") +
theme_cowplot() + xlim(0, 10) + ylim(0,15)

marg1<-ggMarginal(p1, color = "red")
marg2<-ggMarginal(p2, color = "blue")

ggdraw()+
draw_plot(marg1) +
draw_plot(marg2)`

example_ggexra_1

What I'm interested in is to be able to visualize the "y" axis of each marginal plot in order to evaluate the differences in density distribution.

Thanks in advance!

from ggextra.

crew102 avatar crew102 commented on June 9, 2024

Ah, I see what you are saying. This would require passing theme options into ggMarginal, as well as some additional changes to the function itself which would not be easy. I can point you to where in the source code you would have to make changes if you want.

from ggextra.

SebastianoCurreli avatar SebastianoCurreli commented on June 9, 2024

That would be great!
I'll wait for your input then.

from ggextra.

crew102 avatar crew102 commented on June 9, 2024

Take a look at some of the changes I made in this commit: 8f5e4ed. When you rebuild ggExtra with these new changes and run the following:

library(ggplot2)
library(ggExtra)

ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = wt)) +
  ylab("\nmpg") + # need to give extra space for labs with "\n"
  xlab("\nwt") -> p

ggMarginal(p = p, type = "density")

...You should get something like this:

rplot

The alignment of the plots is nice in the example above, but you may have to change the params I've hard-coded to make the alignment work for your specific plot. I've made notes by the diff view on Github here, to help you understand what I was doing.

I don't think we would want to incorporate the ability to customize the marginal plots to the extent that you need, so I would consider this issue closed. @daattali , your thoughts?

from ggextra.

daattali avatar daattali commented on June 9, 2024

from ggextra.

SebastianoCurreli avatar SebastianoCurreli commented on June 9, 2024

Thank you Chris for your prompt help!

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.