@cpad0112
Thanks but your code does not shows me any gene names from my list: do you know how to do it? Thanks
Hi 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
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)
@cpad0112
Thanks but your code does not shows me any gene names from my list: do you know how to do it? Thanks
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)
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
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:

thank you very much!
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")
> 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
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
Log in to answer this question.
Really?
And How to add images to a Biostars post