如何在条形图中重新排序分类值? [R]

时间:2011-11-08 07:55:38

标签: r graph

具体而言,可以分两步重现问题。

(1)将this txt file加载到R with

algae <- read.table('http://www.liaad.up.pt/~ltorgo/DataMiningWithR/DataSets/Analysis.txt',
         header=F,
         dec='.',
         col.names=c('season','size','speed','mxPH','mnO2','Cl','NO3','NH4','oPO4','PO4','Chla','a1','a2','a3','a4','a5','a6','a7'),
         na.strings=c('XXXXXXX'))

(2)用plot(algae$speed)绘图。

分类值将按“高”,“低”,“中”排序。但是,我希望它们是“高”,“中”,“低”。这可能吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

algae$speed <- factor(algae$speed, levels=c("low", "medium", "high"))
plot(algae$speed)