I have a data frame(tcell_pdx_log_wgene_melt) of gene,sample and and an expression value of certain genes. My data frame looks like:
gene    sample                               log_fpkm
ITGB1   Sample_7630_T1_PDX_mousereads        4.4667698
ADIPOR1 Sample_7630_T1_PDX_mousereads        3.7562811
ADIPOR2 Sample_7630_T1_PDX_mousereads        2.4823200
RYK     Sample_7630_T1_PDX_mousereads        2.4521252
JAG1    Sample_7630_T1_PDX_mousereads        1.7713867
ITGB1   Sample_NYA_MT.05_primary_mousereads  1.9555776
ADIPOR1 Sample_NYA_MT.05_primary_mousereads  1.7365991
ADIPOR2 Sample_NYA_MT.05_primary_mousereads  2.1131181
RYK     Sample_NYA_MT.05_primary_mousereads  1.1464496
JAG1    Sample_NYA_MT.05_primary_mousereads  0.6931472
ITGB1   Sample_7630_T1_PDX_humanreads        4.5363987
ADIPOR1 Sample_7630_T1_PDX_humanreads        3.5718399
ADIPOR2 Sample_7630_T1_PDX_humanreads        2.4756977
RYK     Sample_7630_T1_PDX_humanreads        1.8449842
JAG1    Sample_7630_T1_PDX_humanreads        1.7451918
The below plot puts these genes alphabetically but I want the plot to be sorted by one of the variable types " Sample_7630_T1_PDX_humanreads"
 tcell_pdx_log_wgene_melt$sample <- as.character(tcell_pdx_log_wgene_melt$sample)
 tcell_pdx_log_wgene_melt$sample <- factor(tcell_pdx_log_wgene_melt$sample, levels=unique(tcell_pdx_log_wgene_melt$sample))
 p <- ggplot(tcell_pdx_log_wgene_melt,aes(gene,log_fpkm,group=sample)) + 
             geom_point()
 p + geom_line(aes(color=sample))
 
     
    
