Boxplot of contrasts and genes together
1
0
Entering edit mode
17 months ago
bioinfo8 ▴ 230

Hi,

I have 4 strains: A,B,C, D each with mutant and wild samples. I ran differential expression analysis with two designs: 1) design = ~ Condition to get differentially expressed genes for contrast mutant_vs_wild 2) design = ~ Condition_strains to get differentially expressed genes for contrast mutant_A_vs_mutant_B

Now I want to make a boxplot as follows from res object for multiple genes: enter image description here

Please advise. Thanks.

boxplot deseq2 expression • 962 views
ADD COMMENT
0
Entering edit mode

Where are you stuck ? You need to dig into ggplot2 functions

ADD REPLY
0
Entering edit mode
17 months ago
Papyrus ★ 3.0k

The key is to use different aesthetics in ggplot2 to subdivide your data. See this example:

library(ggplot2)
library(stringr)
library(reshape2)

# Generate example expression data
cts <- matrix(rnorm(3*32),3,32)
rownames(cts) <- c("gene1","gene2","gene3")
colnames(cts) <- c(
  rep("A_mutant",4),rep("A_wild",4),
  rep("B_mutant",4),rep("B_wild",4),
  rep("C_mutant",4),rep("C_wild",4),
  rep("D_mutant",4),rep("D_wild",4))

# Tidy-up and build variables
cts <- reshape2::melt(cts)
cts$type <- stringr::str_split_fixed(cts$Var2,"_",2)[,2]
cts$strain <- stringr::str_split_fixed(cts$Var2,"_",2)[,1]

# Select gene
cts.gene1 <- cts[cts$Var1 == "gene1",]
# Plot and fill by strain
ggplot(cts.gene1, aes(x = type, y = value, fill = strain)) + geom_boxplot()
ADD COMMENT
0
Entering edit mode

Thanks Papyrus, Basti. I am struggling with how to make the final dataframe from two designs I mentioned which include retrieving counts for the same gene ( I have a list of 20 genes) from multiple contrasts and generate a big figure with all genes together.

ADD REPLY
0
Entering edit mode

The counts for your gene are independent from the contrasts you do, you should retrieve them from your count/expression matrix, which should look like the example I generated for you. I still do not understand the issue if you do not show the starting data.

To generate a "big" figure such as the one you showed, you produce independent figures for each gene in ggplot2 and then use packages such as cowplot or patchwork to arrange them in a panel. I suggest reading documentation on those.

ADD REPLY

Login before adding your answer.

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