如何更改ggplot2条形图中fill()的颜色谱图? [英] How to change the color spectrum pattern of fill() in ggplot2 bar chart?

查看:1574
本文介绍了如何更改ggplot2条形图中fill()的颜色谱图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我有一个ggplot2脚本,我会在我的问题结尾处显示它,并且在其他朋友的帮助下创建它从这里



但是它的色谱对我来说并不令人满意。



在我旧的barplot()脚本中,我有一行显示每个栏的不同色谱 - > col = c(fill =彩虹(25)),,这种彩虹色与 ggplot(fill = legend)色谱不同。在我最近的ggplot2脚本中,是否有任何方法可以使用以红色开始的彩虹光谱而不是以橙色开头的ggplot2光谱?
如果可能,请添加适当的行我的脚本或提到的脚本和我必须插入它们的位置,因为我已经尝试了几个实例,但它们并不适用于我&看来每个命令的请求对整个程序都有一定的影响。

预先感谢您

<$ p (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),等级= 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:染色质结构和动力学,C:能量产生和转换,D:细胞周期控制,细胞分裂,染色体分配,E:氨基酸转运和代谢,F:核苷酸转运和代谢G:碳水化合物转运和代谢H:辅酶转运和代谢I:脂质转运和代谢J:翻译,核糖体结构和生物发生K:转录L:复制,重组和修复,M:C细胞运动,O:翻译后修饰,蛋白质周转,分子伴侣,P:无机离子转运和代谢,Q:次级代谢物生物合成,运输和分解代谢, R:一般功能预测,S:功能未知,T:信号转导机制,U:细胞内运输,分泌和囊泡运输,V:防御机制,W:细胞外结构 ,Y:核结构,Z:细胞骨架),
频率= 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(),color =seashell)
p + guides(fill = guide_legend(ncol = 1))+
xlab(Factor Class)+
ggtitle(COG函数分类的共识序列)




(尽管它不是一个好的色阶)


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")

解决方案

scale_fill_manual(values=rainbow(25))

(it's not a good colour scale though)

这篇关于如何更改ggplot2条形图中fill()的颜色谱图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆