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

Adding y-axis labels on the marginal plots #64

Open
lavkan opened this issue Sep 13, 2017 · 12 comments
Open

Adding y-axis labels on the marginal plots #64

lavkan opened this issue Sep 13, 2017 · 12 comments

Comments

@lavkan
Copy link

lavkan commented Sep 13, 2017

Hi,

I would like to add y-axis labels for the marginal plots. Is there a way to do it using ggMarginal command?

Thanks,
Lavanya

@daattali
Copy link
Owner

There is no way to do that, the axis labels on the marginal plots are purposely explicitly suppressed. If you absolutely need them, you can modify the source code to NOT remove the labels

@lavkan
Copy link
Author

lavkan commented Sep 13, 2017

It makes sense to remove the axis that are shared, but what about the other axis of these plots? For example, the x-axis of the marginal plot on the top is removed. However, I want the y-axis along with its units printed. I also want to add the y-axis label "count". If there is a way to add this in the ggMarginal function, it would be greatly helpful for the users. Thanks.

@daattali
Copy link
Owner

I suppose that could make sense for histograms. I don't think I will implement this parameter, but I will leave the issue open so that someone in the future could add support for it

@bencneely
Copy link

I'm in agreement with lavkan. I was asked by a reviewer to succinctly display sample size. A histogram worked great to display distribution in the margin, but I'm still lacking magnitude. Being able to add y-axis counts on histograms would be beneficial, in my opinion. Thanks for a great package!

@daattali
Copy link
Owner

@bencneely feel free to submit a pull request if you want to work on this!

@davidizquierdogomez
Copy link

I'm in agreement with lavkan. I was asked by a reviewer to succinctly display sample size. A histogram worked great to display distribution in the margin, but I'm still lacking magnitude. Being able to add y-axis counts on histograms would be beneficial, in my opinion. Thanks for a great package!

yes, that's my case as well. I'm a reviewer in this case and I fully recommend the axis of marginal plots...

@daattali
Copy link
Owner

I understand that can be a useful feature. I would welcome anyone who wants to tackle this feature and implement it - I'll very happily accept that feature

@davidizquierdogomez
Copy link

Thanks you your answer. I would like to but I'm an experienced beginner so it'll be a bit difficult to do it for the moment but maybe in the future ;D

@ms-gx
Copy link

ms-gx commented Jul 3, 2021

@daattali can you tell me where I have to modify your code in order to show the y-axis for histogram marginal plots?

@daattali
Copy link
Owner

daattali commented Jul 4, 2021

@ms-gx I haven't touched the core functionality of this package in 3+ years so I can't tell you. It would need to be found out by walking through the code, with a debugger perhaps

@crew102
Copy link
Contributor

crew102 commented Jul 5, 2021

Hey @ms-gx , here's where the main plot grab associated with the histogram is pulled out of the marginal plot, leaving behind all of the axis grobs. You'd have to edit this code so that the axis grobs are pulled out along with the main plot grob.

addTopMargPlot <- function(ggMargGrob, top, size) {
panelPos <- getPanelPos(ggMargGrob)
topMargG <- getMargGrob(top)
gt <- gtable::gtable_add_rows(
x = ggMargGrob,
heights = grid::unit(1 / size, "null"), pos = 0
)
gtable::gtable_add_grob(
x = gt, grobs = topMargG, t = 1, b = 1,
l = panelPos[["l"]], r = panelPos[["r"]],
z = Inf, clip = "on", name = "topMargPlot"
)
}
addRightMargPlot <- function(ggMargGrob, right, size) {
panelPos <- getPanelPos(ggMargGrob)
rightMargG <- getMargGrob(right)
gt <- gtable::gtable_add_cols(
x = ggMargGrob,
widths = grid::unit(1 / size, "null"),
pos = -1
)
gtable::gtable_add_grob(
x = gt, grobs = rightMargG, t = panelPos[["t"]],
b = panelPos[["b"]], r = ncol(gt), l = ncol(gt),
z = Inf, clip = "on", name = "rightMargPlot"
)
}
# Helper functions for appending the tableGrob that represents the scatter-plot
# (i.e., the main plot, p) with the marginal plots - one for the x margin and
# one for the y margin (x margin = top plot, y margin = right plot)
getPanelPos <- function(gtableGrob) {
layDF <- gtableGrob$layout
layDF[layDF$name == "panel", c("t", "l", "b", "r")]
}
getMargGrob <- function(margPlot) {
margG <- ggplot2::ggplotGrob(margPlot)
gtable::gtable_filter(margG, pattern = "panel")
}

@ms-gx
Copy link

ms-gx commented Jul 6, 2021

@crew102 Thanks so much! I tried, but couldn't figure it out. So I might have to use another package for marginal plots or just leave it as it is.

Thanks again.

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

No branches or pull requests

6 participants