How can i make some bloxplots from a count table?
1
0
Entering edit mode
4.6 years ago

enter image description hereHi there, I have a count table in a .txt file that has six columns as follows:

Gene Id WT_1 WT_2 WT_3 MUT_1 MUT_2

GENE1 321 5454 6565 564 535 
GENE2 ..... ...... ...... ..... .....

What I would like to do is just boxplot the data like this (see pic). boxplot

Where F1 F2 F3... have to be the name of my genes.

How can i do that?? Thanks in advance

RNA-Seq • 1.8k views
ADD COMMENT
0
Entering edit mode

I have something similar to that but mine is just a count table

Really?

And How to add images to a Biostars post

ADD REPLY
1
Entering edit mode
4.6 years ago

Follow the dummy code below and pay attention to df1 object structure : @ sanchi.andrea

genes=rep(paste0("F",seq(1,10)),2)
conditions=rep(c("Tumor","Normal"),each=10)
data=matrix(rnorm(2000,10,10),20,10)
library(dplyr)
df1=data.frame("genes"=genes,"conditions"=conditions,data)
library(tidyr)
df2=df1 %>% gather(Samples, Expression,X1:X10, -genes,-conditions)
library(ggplot2)
ggplot(df2, aes(x=conditions,y=Expression, fill=conditions))+
    geom_boxplot()+
    facet_wrap(~genes)

Rplot

ADD COMMENT
0
Entering edit mode

@cpad0112

Thanks but your code does not shows me any gene names from my list: do you know how to do it? Thanks

ADD REPLY
0
Entering edit mode

sanchi.andrea unfortunately I can't simulate your data from data description. It would help if you could post example data with sample names, gene names and other variables (good and bad)

ADD REPLY
0
Entering edit mode

Sure, i'll try to past here an example:

geneID  wt_Sample1  wt_Sample2  wt_Sample3  mut_Sample1 mut_Sample2 mut_Sample3
gene1        2201               1579                 1262              2082            2130                  1765
gene2        135                 150                   181              159             128                 134 
gene3       700              377                   247              667                 577             481
gene4     1135              597                        497              1215                1165                    908

tHe variables are wt (good) and mut (bad).

Sorry for the formatting, this is the best I can do. Thanks again

ADD REPLY
0
Entering edit mode

Sorry for the formatting, this is the best I can do. Thanks again

I added markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

ADD REPLY
0
Entering edit mode

thank you very much!

ADD REPLY
0
Entering edit mode
library(ggplot2)
library(dplyr)
library(tidyr)
library(stringr)

df1 %>%
    tibble::rownames_to_column("genes") %>%
    gather("sample", "counts", 2:7,-genes) %>%
    mutate("condition" = str_replace(sample, "_.*", "")) %>%
    mutate(., condition = factor(condition, levels = unique(condition))) %>%
    ggplot(aes(condition, counts, fill = condition)) +
    geom_boxplot() +
    facet_wrap(~ genes, scales = "free")

Rplot01

> df1
      wt_Sample1 wt_Sample2 wt_Sample3 mut_Sample1 mut_Sample2 mut_Sample3
gene1       2201       1579       1262        2082        2130        1765
gene2        135        150        181         159         128         134
gene3        700        377        247         667         577         481
gene4       1135        597        497        1215        1165         908
ADD REPLY
0
Entering edit mode

after running that, i have got this error:

Error in mutate_impl(.data, dots) : Evaluation error: could not find function "str_replace". In addition: Warning message: attributes are not identical across measure variables; they will be dropped

Do you know how to fix it? Thanks

ADD REPLY

Login before adding your answer.

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