fgcz / rawDiag

Brings Orbitrap mass spectrometry data to life; multi-platform, fast and colorful R package
https://bioconductor.org/packages/rawDiag
36 stars 11 forks source link

Split one plot into multiple pages #57

Closed 3H2ORZ closed 4 years ago

3H2ORZ commented 4 years ago

Thanks for developing this great tool! I have 20 raw files to read, plot and export as PDF. Some functions (e.g, cycle time plot) stack all these files together in one page of PDF, which are not readable in the end. Is there a solution to split one into several pages? image

tobiasko commented 4 years ago

Hi @3H2ORZ,

nice to hear that you like our tool! Are you using the Shiny app for plotting or the R command line?

Best, Tobi

cpanse commented 4 years ago

@tobiaskoI guess there is a ggplot option or function to fix that.

3H2ORZ commented 4 years ago

Hi Tobi,

Thanks for reaching out. I am using the R command line to generate the pdf file.

Best, RZheng.

ctrachse commented 4 years ago

Hi 3H2ORZ Since you are using the R command line, I suggest you go with the following approach: Load your data, create a nested data.frame, apply the plot function on your nested data.frame, save as pdf.

I wrote a small test script using the Data included in the package repository PXD006932.Exp3A

res <- PXD006932.Exp3A %>% 
  dplyr::ungroup() %>% 
  ScanFrequMovingOver(.) %>% 
  dplyr::filter(Type == "ms2")

nest_plots <- res %>%
  dplyr::group_by(filename) %>%
  tidyr::nest() %>%
  dplyr::mutate(plot =purrr::map2(data, filename, ~ggplot(data = .x) +
                               geom_line(aes(x = Time, y = Frequency)) +
                               scale_x_continuous(breaks = scales::pretty_breaks(8))+
                               scale_y_continuous(breaks = scales::pretty_breaks(8))+
                               ggtitle(.y) +
                               labs(subtitle = "Plotting number of MS2 per second against retention time") +
                               labs(x = "Retention Time [min]", y = "Scan Frequency [Hz]") +
                               theme_light()))

pdf("test_export.pdf")
print(nest_plots$plot)
dev.off()  

this resulted in a pdf with 24 separate plots each on a single page (see attachement).

Best Christisn test_export.pdf

ctrachse commented 4 years ago

Hi @3H2ORZ

have you tried the suggested solution? Did it work?

best Christian

3H2ORZ commented 4 years ago

Hi Christian,

I tried it several times, but it looked like the function ScanFrequMovingOver cannot be called in my R. It reported: Error in ScanFrequMovingOver(.) : could not find function "ScanFrequMovingOver". Then I used: rawDiag:::ScanFrequMovingOver(.), to successfully call it. I will try to use this method to apply to the other plots.

Thanks for the quick response and your kindest help.

Best, RZheng.