格子条形图 - 订购组

时间:2014-03-01 19:06:43

标签: r lattice

我有整数值的类别,我想按升序显示(1,2,3,...,14 +)。但格子图(1,10,11,12,13,14 +,2,3,...)如何解决这个问题?

d = data.frame(c1 = rep(data$Weeks, 2),
    c2 = c(rep('Count',14),rep('Fit',14)),
    c3 =c(data$Count,data$Fit))
barchart(c3 ~ c1, groups = c2, d, auto.key=list(x=.9, y=.9, corner=c(1,1)),ylab='', xlab='# of Weeks', main='1910-1919')

2 个答案:

答案 0 :(得分:0)

我有类似的问题,但有一个Trellis情节。你可以运行它来检查你的时间点的顺序(我猜周数):

summary(d$c2)

然后你可以使用:

修改它
d$c2<- factor(d$c2, levels=("1","2","3",...,"14+") #make sure the names are the same what you have in your data.

然后你可以运行第一个代码,你会发现它们现在的顺序正确。

答案 1 :(得分:0)

degopwn的回答几乎就在那里。改为

d$c2<- factor(d$c2, 
   c("1","2","3",...,"14+") #make sure the names are the same what you have in your data.

测试我的数据

masi@masi:~/Documents$ Rscript plot.associations.r 
           male.Nij      
 Arr/AHB       :32     
 Digoxin arr   :32     
 Furosemide arr:32     
 Sinus         :32      

           male.Nij 
 Sinus         :32   
 Arr/AHB       :32   
 Digoxin arr   :32   
 Furosemide arr:32   

示例代码

summary(datm)

datm$male.Nij <- factor(datm$male.Nij, c("Sinus", "Arr/AHB", "Digoxin arr", "Furosemide arr"))

summary(datm)