0

I plotted a DotPlot following these incredible steps (https://davemcg.github.io/post/lets-plot-scrna-dotplots/) from David but I could only reach the DotPlot part. I tried to calculate and plot the dendrogram and reorder my data, but I didn't succeed.

My code:

> teste2 %>% filter(bacteria %in% markers) %>%
+     ggplot(aes(x = bacteriophage, y = bacteria, color = eop_index, size = virulence_index)) +
+     geom_point() +
+     scale_color_viridis_c(name = 'EOP') +
+     cowplot::theme_cowplot() +
+     theme(axis.line = element_blank()) +
+     theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
+     ylab('') +
+     xlab('') +
+     theme(axis.ticks = element_blank())

My result: DotPlot

What I need: DotPlot that I based my results

It's important to say that the type of data is different. I'm not working with scRNA data, so I'm adapting to my needs. When I apply the same code of David but change the variable names, the result is completely nonsense and does not reorder the data.

The code:

> mat <- teste2 %>% 
+     filter(bacteria %in% markers) %>%
+     pivot_wider(names_from = bacteriophage, values_from = eop_index) %>% 
+     data.frame() # make df as tibbles -> matrix annoying
> mat <- mat[,-1] #drop gene column as now in rows
> clust <- hclust(dist(mat %>% as.matrix())) # hclust with distance matrix
> ddgram <- as.dendrogram(clust) # create dendrogram
> ggtree_plot <- ggtree::ggtree(ddgram)
> ggtree_plot


> dotplot <- teste2 %>% filter(bacteria %in% markers) %>%
+     mutate(bacteria, factor(bacteria, levels = clust$labels[clust$order])) %>%
+     ggplot(aes(x = bacteriophage, y = bacteria, color = eop_index, size = virulence_index)) +
+     geom_point() +
+     scale_color_viridis_c(name = 'EOP') +
+     cowplot::theme_cowplot() +
+     theme(axis.line = element_blank()) +
+     theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
+     ylab('') +
+     xlab('') +
+     theme(axis.ticks = element_blank())
> plot_grid(ggtree_plot, dotplot, nrow = 1, rel_widths = c(0.5,2), align = 'h')

The result: DotPlot with dendrogram rsrs

Here is a sample of my data: Screenshot of data

If someone could help me, I would appreciate it very much! Thanks in advance!

Obs: I tried to change the variables at different ways, but any of them result a correct dendrogram and reorder the dotplot data sequence.

jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
  • 1
    Welcome to SO! You will be most likely to get your question answered if you create a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – DaveArmstrong Feb 09 '23 at 13:12

0 Answers0