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):
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:
Thanks in advance