-
Notifications
You must be signed in to change notification settings - Fork 19
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
[r] Improve trackplot_combine layout logic #116
Conversation
From offline suggestion, just added some smarter logic to decide whether to put the color legend above/below the side plot. Earlier plots are unchanged, but this new variant will look better: Additional codeexpression_plot_subset <- ggplot2::ggplot(expression[cell_types %in% c("B", "DC"),], ggplot2::aes(cell_types[cell_types %in% c("B", "DC")], gene, fill=cell_types[cell_types %in% c("B", "DC")])) +
ggplot2::geom_boxplot() +
ggplot2::guides(y="none", fill="none") +
ggplot2::labs(x=NULL, y="RNA") +
ggplot2::scale_fill_manual(values=discrete_palette("stallion"), drop=FALSE) +
BPCells:::trackplot_theme()
coverage_no_sidebar <- coverage_plot
coverage_no_sidebar$trackplot$takes_sideplot <- FALSE
plot3 <- trackplot_combine(
list(
scalebar_plot,
coverage_no_sidebar,
gene_plot,
loop_plot,
coverage_plot_narrow,
gene_plot_narrow,
scalebar_narrow
),
side_plot = expression_plot_subset
)
ggplot2::ggsave(plot=plot3, "pre_trackplot_with_low_side.png", width=8, height=8, units="in") |
# Reduce cut-off y-axis labels. Put plots with y axis labels later in the plot list, as they will take layer priority with patchwork | ||
has_y_axis <- vapply(tracks, function(t) is(t, "ggplot") && !is.null(t$labels$y), logical(1)) | ||
tracks <- c(tracks[!has_y_axis], tracks[has_y_axis]) | ||
areas <- c(areas[!has_y_axis], areas[has_y_axis]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's elegant!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with the trackplotting code a little bit and it looks really good now. Even fixed all the issues I mentioned on slack, with the cut off coverage labels and legends. Great job Ben
if (tracks[[i]]$trackplot$keep_vertical_margin) { | ||
collapse_upper_margin[i] <- FALSE | ||
if (i < length(tracks)) collapse_upper_margin[i+1] <- FALSE | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pragmatically speaking and unrelated, isn't it possible to have this done to group by different regions, and only collapse within region? Would probably remove the dependence on comparing last_region
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep the function so that plots are always shown top-to-bottom in the order given, so I didn't want to do any re-ordering in that way. My aim with this is to do as much collapsing as is possible while to keeping the order the same
Add several improvements to the
trackplot_combine
layout logic.For plots without sideplots, before and after are as follows:
trackplot_gene()
color legend to always show both + and - strandtrackplot_scalebar()
to change the font size as requested (before it just affected track height)trackplot_coverage()
to reduce (though not eliminate) the likelihood of the label getting cut offAnd, when
side_plot
is present:Script used for plotting demo (relies on the `pbmc-3k` vignette data)
Before (no sideplot)
After (no sideplot)
Before (with sideplot)
After (with sideplot)
After with a low sideplot (see code from comment below)
(Edited to update plot previews with the later improvements)