Plotting Bar charts in R
1
1
Entering edit mode
2.4 years ago

Hi everyone, I'm new to R plotting functionalities. I'm trying to plot an horizontal stacked bar plot divided in three groups based on my table. The table is this:

                           Uniquely.mapped.Reads Non.uniquely.Mapped.Reads Nuclei      Sample
GC065783_ACTCGCTA-CTCTCTAT               5441281                    476072     50      pooled
GC065783_ACTCGCTA-TATCCTCT               7745233                    415674      1 single-cell
GC065783_ACTCGCTA-GTAAGGAG               5224144                    410210     50      pooled
GC065783_ACTCGCTA-ACTGCATA               6170632                    389391      1 single-cell
GC065783_ACTCGCTA-AAGGAGTA               7321056                    494480     25      pooled
GC065783_ACTCGCTA-CTAAGCCT               7799346                    485494      1 single-cell


and i'm trying to plot to plot it this way (i plotted it manually):

Is there a simple way? Can someone help me?

plot R Graph • 883 views
0
Entering edit mode

Do you have to use R?

2
Entering edit mode
2.4 years ago
benformatics ★ 2.5k
library(ggplot2)
library(reshape2)

data <- chart_table
data$id <- row.names(data) data$Nuclei <- NULL
data <- melt(data)
data$reads <- data$value/1e6
data$variable <- factor(data$variable,levels=c('Non.uniquely.Mapped.Reads','Uniquely.mapped.Reads'))

geom_bar( stat="identity") +
coord_flip() +
facet_grid(Sample~.,scales="free_y") +
xlab('')


A bit crude but it works... not sure what you wanted to do with the Nuclei information...

0
Entering edit mode

The Nuclei information is useless for visualization, i needed it before to classify samples into sampleType :) i tried your code, but there's a problem for data$variable, because it outputs only NAs. Can you explain me what are you trying to do there? Many thanks! edit: I solved! Data$variable is already a factor, so that row of the code is useless! Thank you very much again.

0
Entering edit mode

ya i was just making it so that the non.uniquely.mapped reads were at the top of the stacked barchart (like in the example)