2012-02-10 22 views
3

我想在使用晶格包創建的我的條形圖的條上添加數據值。以下是我的代碼的快照。在條形圖中的數據值標籤的錯誤順序R

不幸的是,欄頂部的數值出現錯誤。例如,在具有3.02E-10值的欄上方顯示4.76E-10等等。有人可以幫我解決這個問題。

enter code here 

p <- barchart (one_cir$Value~one_cir$bias, horiz=FALSE,xlim=select_bias, ylim=yrange, data=one_cir, 
     groups=droplevels(one_cir$Model), 
     xlab=list("RVBS (V)",cex=1.3),ylab=list("Delay (ps)",cex=1.3), 
     main="SVT Circuit Analysis: Delay vs RVBS", 
     panel = function(x,y,...){ 
     panel.barchart(x,y,...) 
     panel.grid(h=-1, v=0, col="gray") 
     panel.text(x,y,label = one_cir$Value, pos=1,cex=1.2) 
       },scales=list(cex=1.2), 
     auto.key=list(x = .81, y = 1, corner = c(0, 0),half=FALSE,points = FALSE, cex=1.2, rectangles = TRUE) 
       ) 
     print(p) 

樣本數據集

bias Circuits Model Temp Corner Parameter Value 

0.0  NOR2 11C 25 3-TT delay_DDC 3.02e-10 

0.3  NOR2 11C 25 3-TT delay_DDC 3.79e-10 

0.6  NOR2 11C 25 3-TT delay_DDC 4.92e-10 

0.0  NOR2 11B 25 3-TT delay_DDC 2.90e-10 

0.3  NOR2 11B 25 3-TT delay_DDC 3.66e-10 

0.6  NOR2 11B 25 3-TT delay_DDC 4.76e-10 
+0

請添加你所得到的一個spanshot。我運行你的代碼,它運行良好。 – aatrujillob 2012-02-10 02:31:07

+0

panel.text(x + rep(c(.25, - 。25),3),y,label = one_cir $ Value [order(one_cir $ bias)],pos = 3,cex = 1.2)更多,稍後會提供更全面的答案 – 2012-02-10 20:00:30

回答

2

我沒有晶格親,但下面的調整到panel.text()函數正確排序的標籤,並把上面的標籤他們的各酒吧,而不是與酒吧重疊:

panel.text(x + rep(c(.25, -.25), 3), y, label = one_cir$Value[order(one_cir$bias)], pos = 3, cex = 1.2) 

這是我得到的輸出:

lattice barchart with labels

我不知道是否有更多的方式得到相同的結果。我也遺漏了xlim和ylim參數,因爲我沒有這些對象。這裏是完整的代碼:

one_cir <- data.frame(bias = c(0.0, 0.3, 0.6, 0.0, 0.3, 0.6), 
    Circuits = rep("NOR2", 6), 
    Model = rep(c("11C", "11B"), each = 3), 
    Temp = rep(25,6), 
    Corner = rep("3-TT", 6), 
    Parameter = rep("delay_DDC", 6), 
    Value = c(3.02e-10, 3.79e-10, 4.92e-10, 2.90e-10, 3.66e-10,4.76e-10) 
    ) 

    library(lattice) 
    p <- lattice:::barchart(Value~bias, horiz = FALSE, data = one_cir, 
      groups = droplevels(Model), 
      xlab = list("RVBS (V)", cex = 1.3), ylab = list("Delay (ps)",cex = 1.3), 
      main = "SVT Circuit Analysis: Delay vs RVBS", 
      panel = function(x,y,...){ 
       panel.barchart(x, y, ...) 
       panel.grid(h = -1, v = 0, col = "gray") 
       panel.text(x + rep(c(.25, -.25), 3), y, label = one_cir$Value[order(one_cir$bias)], pos = 3,cex = 1.2) 
      }, 
      scales = list(cex = 1.2), 
      auto.key = list(x = .81, y = 1, corner = c(0, 0), half = FALSE, points = FALSE, cex = 1.2, rectangles = TRUE) 
    ) 
    print(p) 
相關問題