Question: ggplot expression values as function of samples and classes
1
gravatar for debitboro
2.8 years ago by
debitboro180
Belgium
debitboro180 wrote:

Hi Biostars,

Can anyone helps me on the following. I want to plot the expression values of miRNAs as function of samples using ggplot library. I've a dataframe "reduced_data" containing 50 samples and 3 miRNAs + one column "class" (class of each patient: 6 classes).

reduced_data (ordered by class):

              miRNA1     miRNA2     miRNA3      class
sample1   0.126766967  0.1396135 0.126766967      1
sample2   0.002176183  0.2699439 0.005832450      1
sample3   0.004802792  0.3232242 0.002334003      1
sample4   0.005626610  0.2865383 0.003429664      1
sample5   0.078054375  0.1274370 0.078054375      1
sample6   0.002946872  0.2648828 0.002946872      1
sample7   0.048704970  0.1786870 0.048704970      1
sample8   0.005917859  0.3780041 0.005917859      2
sample9   0.003999677  0.2946423 0.005693926      2
...

I want to use ggplot to plot the value of each miRNA as function of patients and classes, each miRNAx in one colour.

What I want to obtain (samples are stratified by classes):

enter image description here

What I've already tried:

mir1 <- data.frame(samples = rownames(reduced_data), class = reduced_data[,4], value = reduced_data[,1])
mir2 <- data.frame(samples = rownames(reduced_data), class = reduced_data[,4], value = reduced_data[,2])
mir3 <- data.frame(samples = rownames(reduced_data), class = reduced_data[,4], value = reduced_data[,3])
mirs <- list(miRNA1=mir1, miRNA2=mir2, miRNA3=mir3)
df_mirs <- cbind(cat=rep(names(mirs),sapply(mirs,nrow)),do.call(rbind,mirs))
ggplot(df_mirs, aes(samples, value, color=cat)) + geom_line()
# i got this error:
#geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

#By replacing samples by class in aes() function,
ggplot(df_mirs, aes(class, value, color=cat)) + geom_line()

I got the following:

enter image description here

Thanks in advance

expression mirna classes ggplot • 1.2k views
ADD COMMENTlink modified 2.8 years ago by Ido Tamir5.0k • written 2.8 years ago by debitboro180
1
gravatar for Ido Tamir
2.8 years ago by
Ido Tamir5.0k
Austria
Ido Tamir5.0k wrote:

Then add a column sample to "reduced_data" then

library("reshape2")
m <- melt(reduced_data, id.vars=c("samples","class"), variable.name=("miRNA"))
ggplot(m, aes(x=samples,y=value,colour=miRNA))+ facet_grid(. ~ class)

In general in ggplot2 its always bringing the data into the correct form: a long table with one measured value per item http://vita.had.co.nz/papers/tidy-data.pdf

And make your questions more reproducible

ADD COMMENTlink written 2.8 years ago by Ido Tamir5.0k
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: 1577 users visited in the last hour