2015-10-06 43 views
3

我正在學習R,我正在嘗試使用直方圖函數hist()。我的code is here(和粘貼在下面),當我運行它時,軸A)不要在原點連接,並且B)它們沒有足夠延伸到數據集。我看過,沒有找到任何東西,屬性xlim,ylim,axes = FALSE,這些解決方案都不起作用。R直方圖軸對於數據集太小

bluegill = read.table(file="lab2.csv", header="true", sep=",") 
attach(bluegill) 

hist(Length, main="", xlab="Length (mm)", ylab="Number of individuals", col="gray") 

,然後這是所得到的圖中,最大長度爲220的數據集,並且x軸僅前進到200

enter image description here

回答

2

一個簡單的解決方案可以是這樣的:

bluegill = read.table(file="lab2.csv", header="true", sep=",") 
attach(bluegill) 

hist(Length, main="", xlab="Length (mm)", ylab="Number of individuals", col="gray", xaxt = "n") ##no x axis 

請注意,已添加,xaxt = "n"新的選項,可以完全消除x軸。然後,您可以使用另一個命令延遲添加x軸。例如

axis(1, at = seq(0, 200, 20)) 
  • 第一個選項是1,這意味着x軸。
  • 第二個選項代表將在情節中顯示的點(原諒我的英語)。
+2

謝謝你的工作,我也不得不爲y軸做'axis(2,at = seq(0,250,50))'和'yaxt =「n」' –