sort the cluster numbers and data in barplot
1
0
Entering edit mode
3.4 years ago
Maria17 ▴ 40

Hi All,

I'm working on single-cell RNA seq data with the Seurat package.i want to make a barplot with cluster in x-axis and percentage of cell type on the y-axis. i applied dittoseq package and this is my code : dittoBarPlot( object = s.integrated, var = "cell.type", group.by = "seurat_clusters",color.panel = col_vector_samples) in the output picture, my cluster numbers aren't sorted, I tried to sort them but it just sorted the numbers, not the bar (data) itself.

Any recommendations or solutions would be appreciated.

Thanks.

Maria

Seurat dittoseq RNAseq • 5.0k views
ADD COMMENT
0
Entering edit mode
3.4 years ago
ATpoint 85k

Something like this?

example(importDittoBulk, echo = FALSE)

plot1 <- dittoBarPlot(myRNA, "clustering", group.by = "groups")
plot2 <- dittoBarPlot(myRNA, "clustering", group.by = "groups", x.reorder=c(3,1,2,4))

library(patchwork)
plot1 | plot2

enter image description here

ADD COMMENT
0
Entering edit mode

Hello, i merged 6 samples and seurat clusters are in x-axis from 0 to 22 and patient ID is in legend part.i want to show the percentage of each patient in each cluster in barplot . now my x-axis is 0,1,10,11,15,.... . i want to be 0,1,2,3,.... . i reorder the axis but just labels reordered not the data(bars) . i run your code but my x-axis doesnt change.

ADD REPLY
0
Entering edit mode

It's a bit difficult to imagine what's going on. Can you perhaps supply the code that you use to generate the image that's sorted and what the output looks like?

ADD REPLY
0
Entering edit mode

Yes. code : dittoBarPlot(Seurat.integrated, "PatientID", group.by = "seurat_clusters", scale = "percent",color.panel = cols) enter image description here

x axis is seurat clusters by each patients. i want to sort the cluster numbers . instead of 0,1,10 > shows 0,1,2,3,.... thanks.

ADD REPLY
0
Entering edit mode

what happens when you follow ATpoint's code and use the x.reorder parameter, e.g. following color.panel = cols?

ADD REPLY
0
Entering edit mode

when I add x.reorder = c(0:22) it converts number 9 ( last number ) to NA and doesn't change anything else. when I delete x.reorder again shows all clusters but not in order(same as figure) I checked the levels of my clusters is 0:22.

ADD REPLY
0
Entering edit mode

for the record, I think with dittoSeq you probably would have had to look at the order that it uses to determine the "levels" and then indicate those in the order that you want, i.e.:

c(1,2,13,17,18,19,20,21...) and so on.

Did you try dittoSeq after you changed the seurat clusters to factors? That should have worked, too, especially, if you indicated factor(...., ordered = TRUE).

ADD REPLY
0
Entering edit mode

I found the solution in case if someone needs it :

with dittoseq i could not change the order of my x-axis , i don't know why so i used ggplot :

factor(Seurat.object@meta.data$seurat_clusters, levels=c(seq(0,22)))

`ggplot(Seurat.object@meta.data, aes(x=seurat_clusters, fill=PatientID)) + geom_bar(position = "fill")`

Good luck.

ADD REPLY

Login before adding your answer.

Traffic: 1996 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6