我正在尝试用 R 生成一个条形图,条形的宽度不同,条形之间的间距也不同。例如我有一个矩阵
data <- matrix(c(1,2,2,4,7,1,11,12,3), ncol = 3, byrow = T)
colnames(data) <- c("Start", "Stop", "Height")
我想生成一个像这样的图形(抱歉草图):
| __
| __ | |
| | | ________ | |
| | | | | | |
------------------- ------------------
0 1 2 3 4 5 6 7 8 9 10 11 12
据我了解, barplot() 允许您指定宽度,但条形之间的空间只能表示为平均条形宽度的一部分。但是,我想为条形之间的空格指定特定的(整数)数字。
我将不胜感激任何提示/想法!
获得所需内容的一种方法是创建虚拟的空条。例如,
##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)
然后使用绘图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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)