来自箱线图中data.frame的保留订单 [英] Retained order from data.frame in boxplot
问题描述
我有一个data.frame包含有序数据.当我将其绘制在箱线图中时,它会自动按照箱线图的字母顺序进行排序.
I have a data.frame containing ordered data. When I plot it in the boxplot, it automatically sort by alphabetical order by boxplot.
有没有办法在绘图的data.frame中保留顺序?
Is there a way to retain the order in the data.frame in the plotting?
data.frame(按日期排序):
data.frame (ordered by Date) :
Date ID Rate Label
20131103 54232 98 54232 20131103
20131223 32123 94 32123 20131223
20140101 12345 89 12345 20140101
箱线图:
boxplot(data_set$Rate ~ data_set$Label,
data=data_set,
col="yellow",
main=Rate Trend,
las=2, pch=0, outcol="red",
par(mar = c(12, 5, 4, 2)+ 0.1))
在代码上方,自动按ID对数据进行排序,而不是使用data.frame中的顺序.有没有办法在boxplot中的data.frame中保留顺序?我正在使用R v2.12.2.
Above code, automatically sort the data by ID instead of using the order in the data.frame. Is there a way to retain the order in the data.frame in boxplot? I am using R v2.12.2.
谢谢您的帮助.
推荐答案
这是由于要素Label级别的顺序所致.一种可能性:
it is due to the order of the levels of the factor Label. One possibiliy:
with(data_set, boxplot(Rate ~ factor(Label, levels=unique(Label)),
col="yellow",
main="Rate Trend",
las=2, pch=0, outcol="red",
par(mar = c(12, 5, 4, 2)+ 0.1)))
hth
这篇关于来自箱线图中data.frame的保留订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!