uclahs-cds / package-BoutrosLab-plotting-general

Functions to Create Publication-Quality Plots
https://uclahs-cds.github.io/package-BoutrosLab-plotting-general
12 stars 4 forks source link

update barplot documentation for plot.horizontal #163

Closed jarbet closed 5 months ago

jarbet commented 1 year ago

Description

A very common plot we make in the lab is a heatmap with a barplot on the right, using plot.horizontal = TRUE.

For the heatmap, I typically use same.as.matrix = TRUE when not clustering, thus I know the order of row/columns of the input data will exactly match the order in the plot. Then I make sure the barplot data rows are in the same order as the heatmap data rows, and use disable.factor.sorting = TRUE.

However, the order of rows in the heatmap and barplot get misaligned in this approach, that's because create.barplot fills in the bars from the bottom to the top of the plot, although I assumed the opposite (i.e. I thought the order of rows in the barplot would match the order of rows in the input data).

Thus I updated the documentation to try and clarify this.

Closes #...

Checklist

Testing Results

see example in comment below

jarbet commented 1 year ago

Here's a simple example demonstrating the issue:

suppressPackageStartupMessages(library(BoutrosLab.plotting.general));

dataset <- data.frame(
    a = 1:3,
    b = 4:6,
    c = 7:9
    );
dataset$id <- factor(1:nrow(dataset));

heat <- create.heatmap(
    x = dataset[, c('a', 'b')],
    same.as.matrix = TRUE,
    clustering.method = 'none'
    );
barplot <- create.barplot(
    formula = id ~ c,
    data = dataset,
    plot.horizontal = TRUE,
    disable.factor.sorting = TRUE
    );

# notice bars are filled in from the bottom to the top, thus the rows of barplot and heatmap are misaligned
barplot;


# to get rows of barplot and heatmap to match, need to reverse order of barplot rows:
barplot.match.heat <- create.barplot(
    formula = id ~ c,
    data = dataset[nrow(dataset):1,], # this makes the rows of the 2 plots match
    plot.horizontal = TRUE,
    disable.factor.sorting = TRUE
    );
create.multipanelplot(
    plot.objects = list(heat, barplot.match.heat),
    layout.width = 2,
    layout.height = 1
    );