我想在我的情节中绘制几个(现在说 - 现在是5个)片段。我尝试过segment()函数,但它只从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))
,情节看起来像这样:
答案 0 :(得分: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))