2017-04-07 48 views
0

我希望我的x軸顯示範圍0到6(共7個刻度)。我輸入以下數據,但第一個字符不顯示 - 所以最後的刻度沒有標籤,並且0不出現。 (我試圖用一個非零數字開始和仍然沒有工作,所以我知道這不是問題!) 我的編碼是這樣的:爲什麼我的x軸的第一個字符不會顯示在圖中?

x=0:6 

probdist = dhyper(x,6,30,6) 

plot(probdist, main="Probability Distribution Function", xlab = "Amount of Numbers Matched", ylab="Probability of Amount of Numbers Matched", xaxt = "n") 

lab = c("0","1","2","3","4","5","6") 

axis(side=1, at = x, labels = lab) 

我怎樣才能獲得x-axis展示它的範圍從0到6?只是用plot功能,具有xaxt = "n"取出,結果範圍爲1至7

回答

0

簡短的回答:加入xlim=range(x)plot功能,你是好去。

x=0:6 

set.seed(1234) 
probdist = dhyper(x,6,30,6) 

plot(probdist, main="Probability Distribution Function", xlab = "Amount of Numbers Matched", 
    ylab="Probability of Amount of Numbers Matched", xaxt = "n", xlim=range(x)) 

lab = c("0","1","2","3","4","5","6") 

axis(side=1, at = x, labels = lab) 

這將返回

enter image description here

的原因,axis功能不加0是由於該地塊已經被創建,它只是修改現有的情節。

+0

是的,它現在在x軸上顯示0!但是,數據已被移至右側 - 沒有數據點出現在「0」上,並且應該爲零的數據點出現在1滴答的上方。 (最高的數據點是當x = 1時 - 不是2,如圖中所示) – Jessie

+0

@Jessie在這種情況下只寫'xlim = c(1,6)'。 –

相關問題