Plotting Bar charts in R
1
1
Entering edit mode
5.0 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:

head(chart_table)

                           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):

Screenshot-2019-05-07-at-19-29-53

Is there a simple way? Can someone help me?

plot R Graph • 1.6k views
ADD COMMENT
0
Entering edit mode

Do you have to use R?

ADD REPLY
2
Entering edit mode
5.0 years ago
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'))

ggplot(data, aes(fill=variable, y=reads, x=id)) + 
  geom_bar( stat="identity") +
  coord_flip() +
  facet_grid(Sample~.,scales="free_y") +
  ylab('Number of reads (millions)') +
  xlab('')

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

ADD COMMENT
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.

ADD REPLY
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)

ADD REPLY

Login before adding your answer.

Traffic: 2008 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