2014-08-27 35 views
0

我想在我的地塊上繪製幾個(現在可以說 - 5)細分。我已經嘗試了segments()函數,但它只繪製了5個給定座標中的兩個線段。下面是代碼:地塊上的細分

begs <- c(34573131,35072050,35471145, 35746065,36504818) 
    ends <- c(34887083,35139735,35557793,35789178,36950091) 
    step <- 820000 

    plot(1, xlim = c(33900000,38000000), axes = F, xlab="Position") 
    axis(1, at = seq(33900000,38000000, by=step), labels=format(seq(33900000,38000000, by=step)/1e6, scientific=F, digits=3)) 
    axis(4, at = seq(0,2,length.out = 5), labels = seq(0,2,length.out = 5)) 
    segments(x0 = begs, x1 = ends, y0 = c(0.1, 0.5 , 0.9 ,1.4, 1.9)) 

,情節看起來像這樣: segments

+1

你Y軸不夠長。將'ylim = c(0,2)'添加到'plot()'命令中。 – 2014-08-27 14:23:23

回答

1

您對plot()第一個電話使R鍵計算x和y的範圍。因此,如果您在第一次通話中的數據不能代表範圍,則需要手動指定範圍。

具體而言,加ylim=c(...)到您的通話plot()

試試這個:

min <- 33900000 
max <- 38000000 

plot(1, xlim = c(min, max), ylim=c(0, 2), 
    axes = FALSE, xlab="Position", ylab="", type="n") 

axis(1, at = seq(min, max, by=step), labels=format(seq(min, max, by=step)/1e6, 
    scientific=F, digits=3)) 
axis(4, at = seq(0,2,length.out = 5), labels = seq(0,2,length.out = 5)) 
segments(x0 = begs, x1 = ends, y0 = c(0.1, 0.5 , 0.9 ,1.4, 1.9)) 

enter image description here