1

I am making CDF plots using this line of code:

library(ggplot2)
ExpDF <- data.frame(x=c('gene1','gene2','gene3','gene4'),"FC"=c(1,2,3,4))
ts_miR_15 <- data.frame(x=c('gene1','gene3','gene4'),"FC"=c(1,3,4))
ahc_miR_15_3UTR <- data.frame(x=c('gene1','gene4','gene12'),"FC"=c(1,4,12))

g <- ggplot(data = NULL)
g + geom_step(aes(x=ExpDF$FC, color="All_genes"),stat="ecdf") +
    geom_step(aes(x= ts_miR_15$FC, color="Targetscan_miR-15/16"), stat="ecdf") + 
    geom_step(aes(x= ahc_miR_15_3UTR$FC, color="3UTR_miR-15/16_seed"), stat="ecdf") +
    scale_colour_manual("Subsets", values = c("All_genes"='black',
                        "Targetscan_miR-15/16"='orange',
                        "3UTR_miR-15/16_seed"='red'))

...(etc. for each additional data.frame

I would like to be able to reorder the labels for the legend such that "All_genes" is on top (and preferably have it in any oder I want). I would prefer to keep the data.frames separate because they have different numbers of genes (which mark the rows) in them and some of them are subsets of the other.

John Gagnon
  • 825
  • 1
  • 8
  • 20
  • You need to reorder them as.factors. – M-- Jun 23 '17 at 16:56
  • In case you want to know how to reorder not only in reverse but as desired: https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame – M-- Jun 23 '17 at 17:00
  • Thank you for the comments, I have seen those other posts but they refer to plotting a single data.frame and not multiple where I want to use my own labels and colors in a specific order for each data.frame. @Masoud, could you explain how I would apply as.factors in this case to reorder the labels? – John Gagnon Jun 23 '17 at 17:04
  • 1
    @JohnGagnon Yes. If you provide a reproducible example. Please read [How to make a great reproducible example in R?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – M-- Jun 23 '17 at 17:06
  • That's not reproducible code. `etc.`? you can make a minimal example by making only two or three data frames and not completed records of them. don't use `...` or `etc.`. – M-- Jun 23 '17 at 18:00
  • @Masoud Sorry, I was trying to make it clear that there was a much larger data set and that the number of rows in each data.frame is different. I have tried to make the code reproducible. Thanks! – John Gagnon Jun 23 '17 at 22:25

0 Answers0