问题描述
我的代码如下所示:
read.table("GO.txt",header=T,sep=',')->go
library(lattice)
barchart(go[,1]~go[,2],horiz=F,ylim=c(30,29666),
layout=c(1,1),stack=F,
auto.key=list(space='right'),
ylab="Yes",
scales=list(x=list(rot=45),y=list(log = T)))
但是,我不想绘制带有x排序的图表,该怎么办?格对我不需要的数据进行了排序.
However, I don't want to plot a chart with sorted x, what should I do?The lattice sorted my data which I don't need.
数据:
number_of_A-Unigene Class Ontology
45 biological adhesion biological_process
5328 biological regulation biological_process
8 carbon utilization biological_process
6 cell killing biological_process
119 cell proliferation biological_process
3248 cellular component organization or biogenesis biological_process
16594 cellular process biological_process
244 death biological_process
4354 developmental process biological_process
3547 establishment of localization biological_process
917 growth biological_process
429 immune system process biological_process
3716 localization biological_process
30 locomotion biological_process
15726 metabolic process biological_process
4182 multicellular organismal process biological_process
1673 multi-organism process biological_process
877 negative regulation of biological process biological_process
10 nitrogen utilization biological_process
11 pigmentation biological_process
640 positive regulation of biological process biological_process
4808 regulation of biological process biological_process
2462 reproduction biological_process
2437 reproductive process biological_process
7812 response to stimulus biological_process
190 rhythmic process biological_process
2001 signaling biological_process
2 sulfur utilization biological_process
44 viral reproduction biological_process
19852 cell cellular_component
1763 cell junction cellular_component
19852 cell part cellular_component
31 extracellular matrix cellular_component
9 extracellular matrix part cellular_component
686 extracellular region cellular_component
30 extracellular region part cellular_component
3698 macromolecular complex cellular_component
9829 membrane cellular_component
3432 membrane part cellular_component
1439 membrane-enclosed lumen cellular_component
15252 organelle cellular_component
6024 organelle part cellular_component
1753 symplast cellular_component
216 antioxidant activity molecular_function
15917 binding molecular_function
15103 catalytic activity molecular_function
2 channel regulator activity molecular_function
433 electron carrier activity molecular_function
319 enzyme regulator activity molecular_function
8 metallochaperone activity molecular_function
522 molecular transducer activity molecular_function
708 nucleic acid binding transcription factor activity molecular_function
26 nutrient reservoir activity molecular_function
102 protein binding transcription factor activity molecular_function
6 protein tag molecular_function
613 receptor activity molecular_function
1039 structural molecule activity molecular_function
5个翻译调节子的活性Molecular_function2478转运蛋白的活动分子功能
5 translation regulator activity molecular_function2478 transporter activity molecular_function
推荐答案
格"采用因子变量并将其按默认(字母顺序)排列.您可以更改顺序.也许:
"Lattice" took your factor variables and arranged them in default (alphabetical) order. You can change the order. Perhaps:
go[,2] <- factor( go[,2] unique(as.character(go[,2])) )
这应该将级别设置为与您在分页浏览时第一次出现的顺序相同.另一个等效项(尽管更像巴洛克式)是:
This should set the levels in the same order as they would first appear if you were paging through them. Another equivalent, although more Baroque, assignment would be:
go[,2] <- factor( go[,2] as.character( go[,2][!duplicated(go[,2])]) )
然后做你的情节. (我没有尝试输入您的数据.它们看起来太乱了.嗯,实际上,我确实用制表符作为分隔符给了它一个镜头.如果它们曾经有制表符,那么它们会丢失,并且元素数量不定如果空格是分隔符.)
Then do your plot. (I did not attempt to input your data. They looked to be too messy. Well, actually I did give it a shot with tabs as the separator. If they once had tabs. then they lost them, and there are variable numbers of elements if white-space is the separator.)
使用重复问题中的数据,标签未排序:
Using the data in the duplicate question the labels are not sorted:
go[[2]] <- factor(go[[2]], levels=unique(as.character(go[[2]])))
这篇关于如何用未排序的x轴(格子)绘制条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!