Question: Geom_bar plot with several x-axis variables
0
gravatar for sking
26 days ago by
sking0
sking0 wrote:

Hi, I'm trying to create a bar plot whose x-axis has several variables (measuring gene expression in two genotypes with three treatment conditions collected on various days (after disease induction)).

Ideally the graph would be depicted by day on the x-axis (0, 1, 3, 5). Each day would have genotypes in opposing colors and treatments ordered within genotype. I found this post that is similar Example graph but the answer using iris data lacks one variable (genotype).

Here's what the data look like:

# A tibble: 24 x 6

sample genotype treatment   day gene1 gene2
<dbl> <chr>    <chr>     <dbl> <dbl> <dbl>
1      1 WT       Control    0 1     0.933
2      2 WT       Treatment1 0 1.09  6.73
3      3 WT       Treatment2 0 0.759 7.78
4      4 KO       Control    0 0.725 0
5      5 KO       Treatment1 0 0.624 0
6      6 KO       Treatment2 0 0.820 0 
7      7 WT       Control    1 0.863 0.821
8      8 WT       Treatment1 1 0.991 5.45 
9      9 WT       Treatment2 1 0.871 7.21
10     10 KO       Control   1 0.634 0
# ... with 14 more rows

Thanks in advance!

x-axis bar plot R ggplot2 • 90 views
ADD COMMENTlink written 26 days ago by sking0

What have you tried? What does your ggplot code look like right now?

ADD REPLYlink written 26 days ago by RamRS30k

I've tried this but I get stacked bars because of the treatment. I just don't know how to add in another 'layer' to the x-axis.

ggplot(data, aes(x=day, y=gene1, fill=genotype))+geom_bar(stat = "identity", position = "dodge", color ="black")
ADD REPLYlink modified 26 days ago • written 26 days ago by sking0

I also tried to reshape the data as described in this post, but since I have three non-continuous variables it doesn't seem to work :/

ADD REPLYlink written 25 days ago by sking0

I have a feeling you're trying to visualize too many variables in a single static plot. If you need individual non-stacked bars, your x needs to be treatment, not day. Try using that to plot for a single value of day. You can then use facets to add in the day component.

ADD REPLYlink written 25 days ago by RamRS30k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1230 users visited in the last hour