在条形图中指定条形之间的空格

ros*_*chu 5 plot r

我正在尝试生成一个条形图,其中R具有不同宽度的条形和它们之间的不同空格.例如,我有一个矩阵

data <- matrix(c(1,2,2,4,7,1,11,12,3), ncol = 3, byrow = T)
colnames(data) <- c("Start", "Stop", "Height")
Run Code Online (Sandbox Code Playgroud)

我想生成一个这样的数字(抱歉草图):

|                                 __ 
|   __                           |  |
|  |  |      ________            |  |
|  |  |     |        |           |  |
------------------- ------------------
0  1  2  3  4  5  6  7  8  9  10 11 12
Run Code Online (Sandbox Code Playgroud)

据我所知,barplot()允许您指定宽度,但条形之间的空间只能表示为平均条宽的一部分.但是,我想为条形之间的空格指定特定的(整数)数字.我会感谢任何提示/想法!

csg*_*pie 4

获得你想要的东西的一种方法是创建虚拟的空条。例如,

##h specifies the heights
##Dummy bars have zero heights
h = c(0, 2, 0, 1, 0, 3)
w = c(1, 1, 2, 3, 4, 1)
Run Code Online (Sandbox Code Playgroud)

然后使用绘图barplot

##For the dummy bars, remove the border
##Also set the space=0 to get the correct axis
barplot(h, width=w, border=c(NA, "black"), space=0)
axis(1, 0:14)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述