JEFworks-Lab / STdeconvolve

Reference-free cell-type deconvolution of multi-cellular spatially resolved transcriptomics data
http://jef.works/STdeconvolve/
98 stars 12 forks source link

Visualization-deconvolved cell types #28

Closed Pedramto89 closed 1 year ago

Pedramto89 commented 1 year ago

I attempted to visualize some of the results but when I apply the commands, I cannot see the deconvolved cell types properly or distinctly. Also, I should mention that: 1- I get no error. Just the visualized images do not seem to be proper ones. 2- I do follow this link for my analysis: https://github.com/JEFworks-Lab/STdeconvolve/blob/devel/docs/visium_10x.md I hope I am on the right way.

1Rplot01 Rplot02 Rplot03 Rplot04

bmill3r commented 1 year ago

Hi @Pedramto89,

You are on the right track! You just need to adjust some of the plotting parameters. For instance, for vizAllTopics(), try setting the parameter lwd to something really small, like lwd=0.01. This basically controls the thickness of the circle stroke. My guess is that it is too thick for your specific plot and so all you are seeing are the outer gray circle strokes and not the inside of the scatterpies. As for the VizTopic() plots, you probably need to set the size of the points to be smaller using the parameter size. I would recommend the same for the vizGeneCounts(). Also, in general, I would increase the dimensions of the plots you are rendering. If you are outputting them as pdfs using ggplot2::ggsave(), then increase the width and height parameters. If you are visualizing them in RStudio in an RMarkdown, you can increase the size of the inline plots using

{r fig.width=24, fig.height=12}

for example.

Hope this helps, Brendan

Pedramto89 commented 1 year ago

Thank you @bmill3r for your prompt response!

I made the change for lwd=0.01 but nothing changed and I got the same result, an image with no deconvolved cell type. Also, tried to add ggsave but got an error with this code:

`plt <- vizAllTopics(theta = deconProp, pos = pos, r = 45, lwd = 0.01, showLegend = TRUE, plotTitle = NA) + ggplot2::guides(fill=ggplot2::guide_legend(ncol=2)) +

ggplot2::geom_rect(data = data.frame(pos), ggplot2::aes(xmin = min(x)-90, xmax = max(x)+90, ymin = min(y)-90, ymax = max(y)+90), fill = NA, color = "black", linetype = "solid", size = 0.5) +

ggplot2::theme( plot.background = ggplot2::element_blank() ) +

ggplot2::guides(colour = "none") + ggplot2::ggsave(plt,width = 24,height = 12,device = NULL)`

Error: Error inggplot2::ggsave(): !device` must be "NULL", a string or a function.

Backtrace:

  1. ggplot2::ggsave(plt, width = 24, height = 12, device = NULL)`
bmill3r commented 1 year ago

Hi @Pedramto89,

Perhaps lwd=0.01 is still too large. Maybe try lwd=0.0 instead.

Also, for ggplot2::ggsave(), check out the documentation here. Basically, device should be something like "pdf". For example, given your ggplot2 object is called plt:

ggplot2::ggsave(filename = "results.pdf",
                plot = plt,
                 device = "pdf",
                 scale = 1,
                 width = 12,
                 height = 12,
                 units = c("in")
                )
Pedramto89 commented 1 year ago

I tried to visualize with only cnaging lwd to 0.0 but got the same result, an image with no deconvolved cell type. Also, added the ggsave but got an error:

Error inggplot_add(): ! Can't addggplot2::ggsave(filename = "plt.pdf", plot = plt, device = "pdf", and scale = 1, width = 12, height = 12, units = c("in"))` to a object.

Backtrace: ▆

  1. └─ggplot2:::+.gg(...)
  2. └─ggplot2:::add_ggplot(e1, e2, e2name)
  3. ├─ggplot2::ggplot_add(object, p, objectname)
  4. └─ggplot2:::ggplot_add.default(object, p, objectname)
  5. └─cli::cli_abort("Can't add {.var {object_name}} to a {.cls ggplot} object.")
  6. └─rlang::abort(...)`
bmill3r commented 1 year ago

Hi @Pedramto89,

As the error states, ggsave() actually isn't added to a ggplot object - it is a stand alone function. You can explicitly tell it which plot to render and save with the plot argument in the function. In this case, given that your ggplot2 object is plt, thus plot = plt in the function.

I'm curious to see how the rendered pdf via ggsave looks.

Thanks and keep me posted, Brendan