【问题标题】:Lattice barchart - ordering groups格条形图 - 排序组
【发布时间】:2014-04-02 20:39:51
【问题描述】:

我想按升序(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')

【问题讨论】:

  • 有没有可能你的整数值类别不是真正的整数,而是“字符”?因此,如果 barchart 正在对其进行排序,那么它会给出您得到的输出。
  • @alexis_laz 'typeof' 表示它们是“整数”
  • 你能让d 可重现吗?也许在dputing 你的d 之后

标签: r lattice


【解决方案1】:

我有类似的问题,但有一个格子图。您可以运行它来检查您的时间点的顺序(我猜是周数):

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.

然后您可以运行第一个代码,您将看到它们现在的顺序正确。

【讨论】:

    【解决方案2】:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 2020-09-01
      相关资源
      最近更新 更多