2016-06-15 60 views
2

我有一個年度x軸1998-2014。正如你可以看到下面的圖片,在每年的前面是一個「X」在每個x軸標籤(年)前奇怪的'X'...如何刪除?

enter image description here 2

如何刪除這個?

我也希望每年在每個酒吧下方垂直寫下。而在紅色和綠色部分可見每欄的值...

我寫了這個代碼:

d=read.delim("LW_Einkommen.csv", sep=";", dec=".", header=TRUE, row.names=1) 
str(d) 

da=data.matrix(d, rownames.force = NA) 
da 

barplot(da, 
     main="ø Einkommen CH Landwirtschaftsbetriebe 1998-2014", 
     xlab="Jahr", 
     ylab="Einkommen pro Betrieb [CHF]", 
     ylim=c(0, 100000), 
     col=c("red","green"), 
     cex.axis = 0.9, cex.lab = 0.9) 

grid(col="black") 

legend("bottomleft", 
     c("Landwirtschaftliches Einkommen","Ausserlandwirtschaftliches Einkommen"), 
     fill=c("red","green")) 
+0

將有很大的幫助,如果你提供你的數據集的前幾行。 –

+2

標籤來自您的數據集的列名稱。數字列名自動附加了一個X.嘗試使用'bar.name'的'names.arg'參數來設置名稱 –

+0

檢查'par'的'las'參數以使標籤垂直。 –

回答

0

謝謝R.德福爲我的3個非常重要imputs! 有了這個,進一步的線程在這裏和整天的修補,我幾乎完成了它。

另一種可能性是增加了read.delimcheck.name=F

d=read.delim("LW_Einkommen.csv", sep=";", dec=".", header=TRUE, row.names=F) 

只是一個小錯誤(我打上標籤部分螺栓)是我的腳本,導致塊標籤在錯誤的順序我堆疊barplot,因爲你可以看到下面的圖片: wrong block-labeling

Acutal以便開始通過所有的紅色塊98red和跳得比綠色塊... 但對方之後應該是一個棒由紅變綠...

d=read.delim("LW_Einkommen.csv", sep=";", dec=".", header=TRUE, row.names=1) 
str(d) 

da=data.matrix(d, rownames.force = NA) 
da 

bp=barplot(da, 
     main="ø Einkommen CH Landwirtschaftsbetriebe 1998-2014", 
     xlab="Jahr", 
     ylab="Einkommen pro Betrieb [CHF]", 
     ylim=c(0, 100000), 
     las=3, 
     col=c("red","green"), 
     cex.axis = 0.9, cex.lab = 1, cex.names=0.9, 
     names.arg = expression("1998","1999","2000","2001","2002","2003","2004","2005","2006", 
           "2007","2008","2009","2010","2011","2012","2013","2014")) 

**# Find the top y position of each block 
ypos <- apply(da, 2, cumsum) 
# Move it downwards half the size of each block 
ypos <- ypos - da/2 
ypos <- t(ypos) 
text(bp, ypos, da, cex=0.7)** 

grid() 

legend("topleft", 
     c("Landwirtschaftliches Einkommen","Ausserlandwirtschaftliches Einkommen"), 
     fill=c("red","green"),cex=0.9) 

貼標我從這裏把模板:https://stackoverflow.com/a/3627269/6467646