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

legend.grob parameterize y position of title #198

Open
jarbet opened this issue Oct 9, 2024 · 0 comments · May be fixed by #199
Open

legend.grob parameterize y position of title #198

jarbet opened this issue Oct 9, 2024 · 0 comments · May be fixed by #199
Assignees

Comments

@jarbet
Copy link
Contributor

jarbet commented Oct 9, 2024

There are situations where sometimes a legend title overlaps with the elements below it (e.g. when manually making a vertical heatmap legend or dotmap legend).

Here is a simple fix I've been using. See argument title.y.coord of my legend.grob2 function:

https://github.com/uclahs-cds/project-disease-ProstateTumor-PRAD-000101-MethySubtypes/blob/main/figures/figure_utilities.R#L1565

https://github.com/uclahs-cds/project-disease-ProstateTumor-PRAD-000101-MethySubtypes/blob/main/figures/figure_utilities.R#L1627

Example

suppressPackageStartupMessages(library(BoutrosLab.plotting.general))

colourkey.labels <- sapply(
    X = seq(0, 6, 2),
    FUN = function(x) {
        return(as.expression(bquote('10'^-.(as.character(x)))));
        }
    );

legend <- legend.grob(
    legends = list(
        legend = list(
            title = expression(bold(underline('q-value'))),
            continuous = TRUE,
            colours = c('white', 'black'),
            total.colours = 100,
            labels = colourkey.labels,
            cex = 1.3, # label text size
            at = seq(0, 100, length.out = length(colourkey.labels)),
            height = 8
            )
        ),
    label.cex = 1.3,
    title.cex = 1.7,
    title.just = 'left',
    title.fontface = 'bold',
    );

create.scatterplot(
    formula = mpg ~ hp,
    data = mtcars,
    legend =  list( 
        right = list( 
            fun = legend 
            )
        )
    );
Screen Shot 2024-10-09 at 3 50 30 PM

Created on 2024-10-09 with reprex v2.0.2

@jarbet jarbet self-assigned this Oct 9, 2024
@jarbet jarbet linked a pull request Oct 9, 2024 that will close this issue
7 tasks
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

Successfully merging a pull request may close this issue.

1 participant