Plotting Grouped Boxplot with ggplot2
1
0
Entering edit mode
3.9 years ago

Hi there,

I like to prepare a grouped boxplot for multiple columns (T1 to T6) from DF below. That can show high and low expression at each time point (T1 to T6). The R script I am using shows only one separate plot at a time e.g. T1 for Exp (High and Low). Any suggestions on how I can combine all columns (T1 to T6) to represent in one plot.

ggplot(DF, aes(x=Exp, y= T1, fill=Exp)) +
geom_boxplot()+
labs(x="T time point", y= "Expression")

DF

Exp T1  T2  T3  T4  T5  T6
High    0.23    0.64    0.00    0.09    0.00    0.36
High    0.12    0.00    0.32    0.05    0.00    0.56
Low 0.01    0.47    0.00    0.41    0.28    0.17
High    0.12    0.04    0.29    0.05    0.13    0.49
Low 0.15    0.00    0.24    0.12    0.00    0.59
R • 7.6k views
ADD COMMENT
3
Entering edit mode

like this?

library(tidyr)
library(dplyr)

gather(df, "time","values", -Exp) %>% 
    ggplot(aes(time,values, fill=Exp, group=Exp))+
    geom_bar(position = "dodge", stat = "identity", width = 0.7)

Rplot

or like this?

gather(df, "time","values", -Exp) %>% 
    ggplot(aes(Exp,values, fill=time, group=time))+
    geom_bar(position = "dodge", stat = "identity", width = 0.7)

Rplot01

ADD REPLY
0
Entering edit mode

I'm surprised OP's data made sense to you - they seem to have many-to-many mappings between time and high/low exp. How one time point can have multiple highs/lows is something I don't get.

ADD REPLY
1
Entering edit mode
3.9 years ago

edited: Thanks to cpad0112,

Your reply was very helpful in solving my issue. For the box plot, I just need to include geom_boxplot().

Thank you!

gather(df, "time","values", -Exp) %>%
ggplot(aes(time,values, fill=Exp, group=Exp))+
geom_boxplot()+
labs(x="time", y= "value")
ADD COMMENT
0
Entering edit mode

Are you sure you meant to mention me and not @cpad0112? They provided the solution, not me.

ADD REPLY

Login before adding your answer.

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