How to use ggplot to boxplot a gene expression dataframe subsetting only a specific gene and dividing my samples in 2 conditions

Viewed 2880

I'm new at R and I have some basic question related to bloxpot. I have a data frame 9800 obs. (these are genes) of 17 variables (these are my samples), and the expression values for those genes. I put a simplified example below.

View(df) 

           sample1   sample2  sample3  

gene1         1         2        25

gene2        5.2        5        32

gene3        3.1        3        50

gene4        2.5       2.6       21

First, I want to associate each sample with a specific condition (responder or no-responder). In this case samples 1 and 2 will be responders and sample3 non-responder. Would work if I create a data frame like this?

condition <- c('responder','responder','non-responder')
sample_condition <- cbind(colnames(df), condition)
View(sample_condition)

sample     condition

sample1    responder

sample2    responder

sample3    non-responder

Now, I want to use ggplot to do a boxplot that shows the expression values of gene1 for the 2 conditions I have designed. example of the boxplot I want. I would like to include the dots for each sample as well

I think my question is really how to tell ggplot() to plot df subsetting only a specific gene and dividing my samples in the 2 conditions I have previously designed.

Thanks in advance!

2 Answers
Related