1

Hi.

I have a ggplot2 script which I will show it at the end of my question and I have created it with the help of other friends from here.

but its color spectrum is not satisfying for me.

In my old "barplot()" script, I had a line that shows the different color spectrum for each bar -> "col=c(fill = rainbow(25))," and this rainbow colors was different from the color spectrum of ggplot(fill=legend). Is there any way to use that rainbow spectrum which begins with red instead of ggplot2 spectrum that begins with orange, in my recent ggplot2 script? if it is possible, please add the appropriate lines in my script or mention the scripts and the position that I have to insert them because I have tried several instances and they did not work for me & it seems that the please of each command has some effect on the whole program.

Thank you in advance

        dat <- data.frame(
  FunctionClass = factor(c("A", "B", "C", "D", "E", "F", "G", "H", "I",     "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "Y", "Z"), levels=c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "Y", "Z")),
  legend = c("A: RNA processing and modification", "B: Chromatin structure and dynamics", "C: Energy production and conversion", "D: Cell cycle control, cell division, chromosome partitioning", "E: Amino acid transport and metabolism", "F: Nucleotide transport and metabolism", "G: Carbohydrate transport and metabolism", "H: Coenzyme transport and metabolism", "I: Lipid transport and metabolism", "J: Translation, ribosomal structure and biogenesis", "K: Transcription", "L: Replication, recombination and repair", "M: Cell wall/membrane/envelope biogenesis", "N: Cell motility", "O: Posttranslational modification, protein turnover, chaperones", "P: Inorganic ion transport and metabolism", "Q: Secondary metabolites biosynthesis, transport and catabolism", "R: General function prediction only", "S: Function unknown", "T: Signal transduction mechanisms", "U: Intracellular trafficking, secretion, and vesicular transport", "V: Defense mechanisms", "W: Extracellular structures", "Y: Nuclear structure", "Z: Cytoskeleton"),
  Frequency=c(360,391,897,1558,1168,448,1030,536,732,1292,2221,2098,789,117,1744,732,437,5162,1251,2191,603,216,2,14,739)
)

library(ggplot2)
p <- ggplot(data=dat, aes(x=FunctionClass, y=Frequency, fill=legend))+
geom_bar(stat="identity", position=position_dodge(), colour="seashell")
p + guides (fill = guide_legend(ncol = 1))+
xlab("Factor Class")+
ggtitle("COG Function Classification of Consensus Sequences")
Community
  • 1
  • 1
Farbod
  • 67
  • 3
  • 12

1 Answers1

0

scale_fill_manual(values=rainbow(25))

(it's not a good colour scale though)

baptiste
  • 75,767
  • 19
  • 198
  • 294
  • Dear Baptiste, Hi and thank you as it works great for me. But why you have said: " it's not a good color scale though" and what scale you suggest to me? Thank you again. – Farbod Sep 25 '16 at 07:23
  • Because no one can meaningfully distinguish 25 different colors in a single plot. The coloring here is just decoration and does not communicate anything about the data. Each color maps to one tick on your x-axis. So why not just rely on the axis labeling? – jdobres Sep 25 '16 at 17:35
  • Hi and thank you. I now get the point and before your description I thought @baptiste means that the "fill()" color spectrum is better than "rainbow()" colors. I think because some x-axis labels are **very long**, using this color legend has became popular. – Farbod Sep 25 '16 at 19:36
  • i do think the rainbow/colorjet palette of colours is a bad choice. See [for example](http://www.sciencedirect.com/science/article/pii/S0167947308005549) or [this one](http://geog.uoregon.edu/datagraphics/EOS/Light-and-Bartlein_EOS2004.pdf) – baptiste Sep 25 '16 at 22:49
  • Thank you for these interesting papers. How I can use "HCL-based" color instead of HSV-based rainbow in my script ? – Farbod Sep 26 '16 at 07:11
  • I think the easiest way is to ignore this answer and your question. See `?scale_colour_hue` (the default scale) – baptiste Sep 26 '16 at 07:14