1

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))
RHA
  • 3,677
  • 4
  • 25
  • 48
user45292
  • 45
  • 1
  • 9
  • 1
    It's unclear what you want sorted, and how you want it sorted. Could you elaborate further? – Heroka Aug 04 '15 at 20:41

1 Answers1

0

Not really sure what you are looking for, but I've dput() and plotted your data below. Maybe you can use that to explain what excatly you are looking to do? If you make a minimal reproducible example to go along with your question. Something we can work from and use to show you how it might be possible to solve your problem. You can have a look at this SO post on how to make a great reproducible example in R.

wassss

tcell_pdx_log_wgene_melt <- structure(list(gene = structure(c(3L, 1L, 2L, 5L, 4L, 
3L, 1L, 2L, 5L, 4L, 3L, 1L, 2L, 5L, 4L), 
.Label = c("ADIPOR1", "ADIPOR2", 
"ITGB1", "JAG1", "RYK"), class = "factor"), 
sample = structure(c(2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L), 
.Label = c("Sample_7630_T1_PDX_humanreads", 
"Sample_7630_T1_PDX_mousereads", "Sample_NYA_MT.05_primary_mousereads"
), class = "factor"), log_fpkm = c(4.4667698, 3.7562811, 2.48232, 
2.4521252, 1.7713867, 1.9555776, 1.7365991, 2.1131181, 1.1464496, 
0.6931472, 4.5363987, 3.5718399, 2.4756977, 1.8449842, 1.7451918
)), .Names = c("gene", "sample", "log_fpkm"), 
class = "data.frame", row.names = c(NA, -15L))

# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)

 p <- ggplot( tcell_pdx_log_wgene_melt,aes(gene,log_fpkm,group=sample))
 +  geom_point()
 p + geom_line(aes(color=sample))
Eric Fail
  • 8,191
  • 8
  • 72
  • 128