如何使用barplot()沿x轴手动指定条形的位置?

如何使用barplot()沿x轴手动指定条形的位置?,r,R,我有一份方法清单 means=c(anc3mean,l3mean,anc5mean,l5mean,anczmean,z12mean);means [1] 0.07025897 0.42328670 0.05697524 0.53915431 0.01893219 0.10878638 我用这些方法创建了一个条形图 bars=barplot(means,ylim=c(0,.8)) 我希望“条”沿x轴以值1、2、4、5、7、8为中心 我尝试了以下方法: bars=barplot(means,y

我有一份方法清单

means=c(anc3mean,l3mean,anc5mean,l5mean,anczmean,z12mean);means
[1] 0.07025897 0.42328670 0.05697524 0.53915431 0.01893219 0.10878638
我用这些方法创建了一个条形图

bars=barplot(means,ylim=c(0,.8))

我希望“条”沿x轴以值1、2、4、5、7、8为中心

我尝试了以下方法:

bars=barplot(means,ylim=c(0,.8),at=c(1,2,4,5,7,8))
但是,这不起作用,因为“at”不是“barplot()”的参数

任何帮助都将不胜感激。

您可以插入“空”元素

# x position of the means
loc <- c(1, 2, 4, 5, 7, 8)

# Fill with empty elements
hght <- setNames(rep(0, max(loc)), 1:max(loc))
hght[loc] <- means

# Plot
x = barplot(hght, ylim = c(0, 0.8))
axis(1, at = x, labels = names(hght))
means <- c(0.07025897, 0.42328670, 0.05697524, 0.53915431, 0.01893219, 0.10878638)