DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

xlim does not work in cyto_plot_save(layout = ...) #165

Open tamaikeiichi opened 1 year ago

tamaikeiichi commented 1 year ago

Describe the bug xlim does not work in cyto_plot_save(layout = ...). In cyto_plot_layout(), it works. Could you fix it?

To Reproduce

setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
##clear all objects
graphics.off()
rm(list=ls())

# Load required packages
library(CytoExploreR)
library(CytoExploreRData)

##select files to analyze
filename <- list.files("./")
filename.subset <- filename[grep(".*.fcs", filename)]

##load files
gs <- cyto_setup("./",
                 select = filename.subset,
                gatingTemplate = "Activation-gatingTemplate.csv")

gs <- cyto_transform(gs, type = "biex")  

cyto_plot_save("cyto_plot_save.pdf",
                 multiple = T,
                 layout = c(2,1))
for(j in 1:2){
    cyto_plot(
      gs[[j]],
      parent = "root",
      channels = c("GFP-A", "SSC-A"),
      xlim = c(10,1000000),
    )
}
cyto_plot_save_reset()
cyto_plot_reset()
##screenshot "cyto_plot_save.png"

cyto_plot_layout(c(2,1))
for(j in 1:2){
  cyto_plot(
    gs[[j]],
    parent = "root",
    channels = c("GFP-A", "SSC-A"),
    xlim = c(10,1000000),
  )
}
##screenshot "cyto_plot_layout.png"

Expected behavior The range of x-axis is set as described in xlim.

Screenshots cyto_plot_save

cyto_plot_save

cyto_plot_layout

cyto_plot_layout

Desktop (please complete the following information): win11, Rstudio, R version 4.2.1, ‘CytoExploreR’ version 1.1.0

Additional context Thank you for your great app!

DillonHammill commented 1 year ago

@tamaikeiichi, I would recommend using the method described on the website under "Custom Plot Layouts" section: https://dillonhammill.github.io/CytoExploreR/articles/CytoExploreR-Visualisations.html

This will be the approach used in the new version of CytoExploreR as well, and layout will be removed from cyto_plot_save().

This is the recommended way to do this:

# 1. open device
cyto_plot_save()
# 2. set layout
cyto_plot_custom()
# 3. add plots
cyto_plot()
# 4. close device
cyto_plot_complete()
tamaikeiichi commented 1 year ago

@DillonHammill , Thank you for your quick response.

I have tried as you mentioned, but it does not still work. Is there any other way?

cyto_plot_save("cyto_plot_custom.pdf")
cyto_plot_custom(layout = c(2,1))
for(j in 1:2){
  cyto_plot(
    gs[[j]],
    parent = "root",
    channels = c("GFP-A", "SSC-A"),
    xlim = c(10,1000000),
  )
}
cyto_plot_complete()
スクリーンショット 2022-09-26 172525
DillonHammill commented 1 year ago

Can you remove the xlim part altogether and send through the plots?

DillonHammill commented 1 year ago

Just pointing out that custom layouts are not actually required in this case. You can call cyto_plot_save() and then cyto_plot() directly:

cyto_plot_save("test.pdf")
cyto_plot(
    gs,
    select = c(1,2),
    parent = "root",
    channels = c("GFP-A", "SSC-A"),
    layout =c(1,2)
  )
DillonHammill commented 1 year ago

I think the issue is that your transformations are not defined over the limits you specify. Try setting xlim = c(10, 1e6).

tamaikeiichi commented 1 year ago

@DillonHammill , Your code xlim = c(10, 1e6) works and X-axis is set correctly. Thank you.

Another problem is that I want to use for() like below because multiple overlay plots are needed. The outcome is no multiple layout in "cyto_plot.pdf". Finally, 24 paired files need to be processed and a PDF file be created as multiple layouts, pages. Could you tell me what's wrong?

cyto_plot_save("cyto_plot.pdf", multiple = T)
for(j in 1:2){
  test <- cyto_extract(gs, parent = "root")[[j+2]]
  cyto_plot(
    gs[[c(j)]],
    parent = "root",
    overlay = test,
    channels = c("GFP-A", "SSC-A"),
    xlim = c(100,1e6),
    point_col = c("blue",
                  "pink"),
    layout = c(2,2)
  )
}
cyto_plot_complete()
DillonHammill commented 1 year ago

What does the plot look like? It should be on one page as you onky require 2 panels but your layout defines 4 panels.

tamaikeiichi commented 1 year ago

@DillonHammill , Here is the PDF file. Only one panel (and one page) was created cyto_plot.pdf

DillonHammill commented 1 year ago

Try running cyto_plot_reset() and then save the plot again.

tamaikeiichi commented 1 year ago

@DillonHammill , Is this code what you expected? No change is seen.

cyto_plot_reset()
cyto_plot_save("cyto_plot.pdf", multiple = T)
for(j in 1:2){
  test <- cyto_extract(gs, parent = "root")[[j+2]]
  cyto_plot(
    gs[[c(j)]],
    parent = "root",
    overlay = test,
    channels = c("GFP-A", "SSC-A"),
    xlim = c(100,1e6),
    point_col = c("blue",
                  "pink"),
    layout = c(1,2)
  )
}
cyto_plot_complete()

cyto_plot.pdf