如何在R中使用ggplot2绘制直向同源群(COG)棒图的群集? [英] How to draw Clusters of Orthologous Groups (COG) bar plot using ggplot2 in R?
问题描述
我是R新手,我有一些数据如下,我想绘制一个与这个与R程序(linux或Rstudio)中的pkg :: ggplot2。
I am new to R and I have some data as below and I want to draw a histogram same as this with pkg::ggplot2 in R program (linux or Rstudio).
正如你所看到的它是X轴(功能类)中从A到Z的字母,Y中的数字是频率,重要的一点是每个小节都有它自己的独特颜色。
As you can see it is the letters from A to Z in the X axis (Function class) and the frequencies as numbers in the Y and the important point is this that each bar has its own unique color.
另外,还有一个 color help = legend ,它用每个条的相同颜色描述每个类,我不确定它是否是R ggplot2包的某些特征?
In addition, there is a "color help = legend" that describe each class by the same color of each bars that I am not sure if it is some characteristics of R ggplot2 package or not?
我检查了一些在线帮助,但我不知道如何在ggplot2中插入我的数据并为每个类指定一个唯一的颜色。
I have checked some online helps but I do not know how to insert my data in the ggplot2 and assign a unique color for each class.
我的数据样本:
my data sample:
A 5 RNA processing and modification
B 2 Chromatin structure and dynamics
C 18 Energy production and conversion
D 26 Cell cycle control, cell division, chromosome partitioning
E 15 Amino acid transport and metabolism
F 5 Nucleotide transport and metabolism
G 13 Carbohydrate transport and metabolism
H 6 Coenzyme transport and metabolism
I 15 Lipid transport and metabolism
J 20 Translation, ribosomal structure and biogenesis
K 24 Transcription
L 28 Replication, recombination and repair
M 18 Cell wall/membrane/envelope biogenesis
N 1 Cell motility
O 29 Posttranslational modification, protein turnover, chaperones
P 19 Inorganic ion transport and metabolism
Q 16 Secondary metabolites biosynthesis, transport and catabolism
R 85 General function prediction only
S 20 Function unknown
T 32 Signal transduction mechanisms
U 14 Intracellular trafficking, secretion, and vesicular transport
V 6 Defense mechanisms
Z 14 Cytoskeleton
推荐答案
那些字母AZ旁边的数字是酒吧的高度?如果是这样,你最好使用barplot:
Are those numbers next to the letters A-Z the height of the bars? If so, you're better of using a barplot:
library(ggplot2)
# Simulate some data
obs = rpois(10, 5)
group = factor(1:10)
df = data.frame(obs, group)
ggplot(data = df, aes(x = group, y = obs, color = group, fill = group)) +
geom_bar(stat = 'identity')
为了获得一般的彩条,确保你的数据框有一个分组变量(必须是一个因子,否则你会得到连续的颜色分配),然后在 aes
分配颜色/填充列名的值。
To get the colored bars in general, make sure your dataframe has a grouping variable (must be a factor, otherwise you get continuous color assignment) and then in aes
assign color/fill the value of the column name.
这篇关于如何在R中使用ggplot2绘制直向同源群(COG)棒图的群集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!