2012-02-24 2 views
4

다음과 같은 큰 데이터가 있지만이 샘플은 거의 없습니다.가로줄 그래프와 함께 assambly R

pos <- c(1, 3, 5, 8, 10, 12) 
start <- c(1,3, 6, 7, 10, 11) 
end <- c(5, 6, 9, 9, 13, 12) 

양자화 적 변수 Pos는 Y 축이고 X 축은 X 변수 (정량적)입니다. 각 Pos 값의 가로 막대 길이는 시작 및 끝 지점으로 정의됩니다. 예를 들어 1 행은 1에서 시작하여 x 축에서 3으로 끝납니다.

다음은 원하는 그림 출력의 대략적인 스케치입니다. geom_segment

enter image description here

+2

마지막 예제 도움이됩니다 ... 당신의 그림과 같이 더 정확하게를 얻으려면? http://had.co.nz/ggplot2/geom_linerange.html –

+0

예, 실제로 .. 도움이됩니다. – jon

답변

3

를 사용하여 패키지 ggplot2는 선을 그립니다. ggplot이 필요한 데이터 구조 때문에, data.frame으로 데이터를 결합하여

시작 :

dat <- data.frame(
    pos = c(1, 3, 5, 8, 10, 12), 
    start = c(1,3, 6, 7, 10, 11), 
    end = c(5, 6, 9, 9, 13, 12) 
) 

플롯을 만들기 : 기본 R에서

library(ggplot2) 
ggplot(dat) + 
    geom_segment(aes(x=start, y=pos, xend=end, yend=pos), color="blue", size=3) + 
    scale_y_reverse() 

enter image description here

4

..

plot(pos, type = 'n', xlim = range(c(start, end)), ylim = c(13,0)) 
grid() 
segments(start, pos, end, pos) 
,

r <- par('usr') 
plot(pos, type = 'n', xlim = range(c(start, end)), ylim = c(13.5,0.5), xlab = '', 
    xaxt = 'n', yaxt = 'n', panel.first = rect(r[1], r[3], r[2], r[4], col = 'goldenrod')) 
# abline(h = 1:13, col = 'white') 
# abline(v = 1:13, col = 'white') 
grid(lty = 1, col = 'white') 
axis(1, 1:13, 1:13, cex.axis = 0.8) 
axis(2, 1:13, 1:13, las = 1, cex.axis = 0.8) 
segments(start, pos + 0.5, end, pos + 0.5, lwd = 2) 
관련 문제