2013-07-23 29 views
1

enter image description here爲什麼R圖中會出現這些差距?

我有這個錯誤每隔一欄填滿,但除了這一個?

data=read.csv("data.csv") 
    attach(data) 
    data$marks<- factor(data$marks, levels = data$marks[order(data$a)]) 
    c.data=melt(data, id.var="marks") 
    n.data = ddply(c.data,.(marks), transform, pos = cumsum(value) - 0.5*value) 

plot = ggplot(n.data, aes(x = marks, y = value)) + 
     geom_bar(stat = "identity",aes(fill = variable)) + 
     geom_text(aes(label = value, y = pos), size = 3, face="bold", 
        colour="white") + 
     scale_fill_manual(values=c("#800000","#000000")) + 
     scale_y_continuous(limits=c(0, 100), breaks=seq(0,100, by = 10)) + 
     theme(axis.line = element_line(), 
       axis.text.x=element_text(angle=60,hjust=1,colour="white"), 
       axis.text.y=element_text(colour="white"), 
       axis.title.x = element_blank(), 
       axis.title.y = element_blank(), 
       panel.background = element_blank(), 
       axis.ticks=element_blank()) + 
     labs(fill="") 

這是我用過

Marks a b 
1 49 51 
2 53 47 
3 54 46 
4 54 46 
5 55 45 
6 55 45 
7 55 45 
8 55 45 
9 55 45 
10 56 45 
11 56 45 
12 56 44 
13 56 44 
14 56 44 
15 56 44 
16 56 44 
17 57 44 
18 57 43 
19 57 43 
20 58 42 
21 58 42 
22 59 41 
23 60 40 
24 60 40 
25 61 39 
26 61 39 
27 61 39 
28 62 38 
29 62 38 
30 62 38 
31 64 36 
32 64 36 
33 67 33 
34 71 29 

這是用於我已經圓潤點,以便它得到整數

+4

您的數據是? –

+0

對不起,有錯誤:( – Zack

+0

並使其成爲實際的數據......這可能是問題的地方。 – John

回答

3

在自己的原始數據的樣本數據的代碼你提供的問題幾行總和爲ab列高於100.

apply(df,1,function(x) sum(x[2:3])) 
[1] 100 100 100 100 100 100 100 100 100 101 101 100 100 100 100 100 101 100 
[19] 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 

因此,當您在熔化後繪製數據並在scale_y_continuous()內設置limits=時,那些超過100的值將從圖中移除。

+ scale_y_continuous(limits=c(0, 100), breaks=seq(0,100, by = 10)) 

解決方案,這是糾正你的數據有ab總和等於100的所有行或刪除從scale_y_continuous()limits=c(0,100)並添加coord_cartesian() - 這將放大你的陰謀限制。

+coord_cartesian(ylim=c(0,100)) 
+0

得到這個錯誤錯誤:找不到函數「ggplot2」 – Zack

+0

我應該刪除scale_y_continuous(限制= c(0, 100),break = seq(0,100,by = 10))this code complete and add coor_cartesian code? – Zack

+0

@Zack no,just remove limits = c(0,100)。參數breaks =可以保留在scale_y_continuous()內關於ggplot2錯誤 - 有沒有函數ggplot2()。函數名是ggplot()。 –

相關問題