这是我的计划
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)
)
library(ggplot2)
p <- ggplot(dat) + geom_segment(aes(x=start, y=pos, xend=end, yend=pos),
color="blue", size=2) + ylab("Fragments)") + xlab("Position")
scale_y_reverse() + theme_bw()
p1 <- p + opts(legend.position="left",
panel.background=theme_blank(),panel.border=theme_blank(),
panel.grid.major=theme_blank(),
panel.grid.minor=theme_blank(),plot.background=theme_blank())
p1
所需的位图版本是,在线段附近有轴线和标签。 [只是额外注意:请注意,位图将线更改为圆角(看看我们是否可以在 ggplot2 中这样做会很有趣)]
最佳答案
有趣的是,我实际上认为这在基础图形中更容易:
plot(c(0,13),c(1,12),type = "n",axes = FALSE,xlab = "Position",ylab = "")
segments(x0 = dat$start,
y0 = dat$pos,
x1 = dat$end,
y1 = dat$pos,
col = "blue",
lwd = 6,
lend = 2)
text(x = dat$start - 0.5,y = dat$pos,labels = dat$pos,font = 2)
axis(1)
axis(1,at = c(0,12),labels = FALSE,tcl = 0.5)
编辑 添加了额外的 axis
调用以在两个方向上获取最外层的刻度。
关于r - 将选定的线保留在 x Axis 上,并在 Y Axis 上的特定部分标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10434108/