DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

cyto_plot_explore function plots are not grouped together #70

Closed siveenks closed 4 years ago

siveenks commented 4 years ago

Briefly describe what you hope to achieve: I was trying to use the cyto_plot_explore function.

Outline the steps taken to attempt to reach this goal (paste code below): I have a gating set, which had gates drawn with CytoExploreR. I can generate grouped plots with cyto_plot_profile and cyto_plot_gating_scheme, where all the plots are generated as a single image. But, for cyto_plot_explore function, each plot is rendered individually. So, I end up having 40 individual plots in 40 popup windows. I was expecting to get a single image as the other functions do. is there any mistake in the way i plot?

cyto_plot_explore(gs[[1]],
                  parent = "root",
                  channels_x = chnls,
                  channels_y = "CD14",
                  layout = c(6,6),
                  axes_trans = NA,
                  popup = T,
                  title = NA
                  )

Include any associated screenshots or images here: image image

DillonHammill commented 4 years ago

@siveenks, thanks for reporting this. I wrote this very quickly a while back and it seems that some changes are required. I just pushed a fix for you to try. I am currently unable to test this locally as I am trying to address some R4.0 related issues on my windows machine. Please pull down the latest CytoExploreR and DO NOT update your RGLab packages (the latest CytoExploreR is still a bit behind these at the moment so some things may not work properly if you update):

devtools::install_github("DillonHammill/CytoExploreR")

I should be able to test this tomorrow and I can work on a more robust solution if required.

siveenks commented 4 years ago

@DillonHammill Now cyto_plot_explore function plots everything in a single image. Thank you. I forgot to mention earlier that the new CytoExploreR package is a great analysis tool for novice users like me. Great work..

Can I ask for some suggestions in the behavior of plotting commands. If I give the function cyto_plot_explore with "layout = c(7,7)" along with popup = (T or F), R will give an error "Error in plot.new() : figure margins too large". Later I am increasing my panel to 45 markers and then I wont be able to do plotting. As of now it is OK, since I have only 42 markers and I can use "layout = c(6,7)" which works.

image

DillonHammill commented 4 years ago

This is just telling you that the plotting window is too small to fit all the plots. There are a couple of things that you can do:

1 - Adjust the layout to reduce the number of plots per page (as you have above):

cyto_plot_explore(gs[[1]],
                  parent = "root",
                  channels_x = chnls,
                  channels_y = "CD14",
                  layout = c(6,6),
                  axes_trans = NA,
                  popup = T,
                  title = NA)

2 - Maximise the available plotting space before plotting. If you are using the RStudio graphics device (i.e. popup = FALSE), you can do this by dragging the size of the plotying window to be as big as possible. A better way is to create a popup device first, make it as big as possible and then make the call to a cyto_plot function:

# open popup window
cyto_plot_new()

# maximise the window then
cyto_plot_explore(gs[[1]],
                  parent = "root",
                  channels_x = chnls,
                  channels_y = "CD14",
                  layout = c(6,6),
                  axes_trans = NA,
                  popup = FALSE,
                  title = NA)

The second approach will allow you to fit more plots on the page but you may still need to adjust the layout argument as well so that you can see everything.

DillonHammill commented 4 years ago

I should also point out that you can use cyto_plot_save() to save the images in as big a graphics device as you want - they won't appear in R but will be saved to a file that can be opened.

cyto_plot_save("test.pdf",
width =15,
height = 15,
multiple = TRUE)

cyto_plot_explore(gs[[1]],
                  parent = "root",
                  channels_x = chnls,
                  channels_y = "CD14",
                  layout = c(6,6),
                  axes_trans = NA,
                  popup = FALSE,
                  title = NA)

The pdf approach above will save each sheet to the same pdf file, which is extremely useful! The same approach can be used for all other cyto_plot() family members.

DillonHammill commented 4 years ago

Oh and the cyto_plot_save method will also plot much faster!

siveenks commented 4 years ago

@DillonHammill The cyto_plot_save method worked in an excellent way and as you said it was really fast also. Thank you for the suggestions and that too very prompt.

I have one doubt, when I draw gates using cyto_gate_draw(gs, parent = "CD4", alias = c("EM CD4", "CM CD4","Naive CD4","TEMRA CD4"), channels = c("CD27","CD45RA"), type = c("q"), xlim = c(-1,3), ylim = c(-1,5), gatingTemplate = "44C-gatingTemplate.csv", contour_lines = 15)

what happens to the events that is exactly on the gate? are they included in any gate or 2 shared gates or are they excluded in gating? is there any way we can specify how it should work for such events?

For example, as shown in the gating strategy figure, the "TEMRA, Naive, CM and EM" populations of "gdT, NKT, CD4 and CD8" cells are created using a quadrant gate. so what will happen to events lying on the gate as shown in the images? will they be considered as "CM" or "Naive" or "not included in both gated population" or "included in both gating population"?

image image

DillonHammill commented 4 years ago

@siveenks that is a good question! In fact I have already addressed this issue in CytoRSuite (the predecessor or CytoExploreR) https://github.com/DillonHammill/CytoRSuite/issues/20. These used to be treated as separate rectangles, which meant the overlapping events were counted twice - this has since been resolved as discussed here https://github.com/RGLab/openCyto/issues/199 and fixed here https://github.com/RGLab/cytolib/issues/16. As you can see above the statistics now add up to 100% or thereabouts accounting for rounding. I don't know the full details of how these events are allocated, @mikejiang do you mind commenting on this?

DillonHammill commented 4 years ago

I think these are the relevant lines: https://github.com/RGLab/cytolib/blob/57c4d0670e5314c5821750bfcd2b521c347b2199/inst/include/cytolib/gate.hpp#L294-L330

So it looks like each quadrant gets one of the crosshair boundaries to prevent duplication of these events.

DillonHammill commented 4 years ago

I think we can close this now. Feel free to post new issues if you need any help @siveeks.