我已经完成了 - 必须将每个条形绘制为矩形,相应地调整xmin和xmax。
wadjust = 5.5 gap = 0.0 minv = 1:length(value) - 0.5 + gap/2 maxv = minv + 1 -gap minv[1:length(minv)%%2!=0] = maxv[1:length(maxv)%%2!=0] - width[order(Activity)][(1:length(width))%%2!=0]/wadjust maxv[1:length(maxv)%%2==0] = minv[1:length(minv)%%2==0] + width[order(Activity)][(1:length(width))%%2==0]/wadjust minv = minv +0.525 maxv = maxv +0.525 minvord = minv[order(Activity)] maxvord = maxv[order(Activity)] ggplot(molten, aes(x=activity,width = width/6, fill = variable)) + geom_rect(xmin = minv,xmax = maxv, ymin = rep(0,28), ymax = value[order(Activity)], fill = rep(c('#e1de00','#e84619'),len=28)) + theme(axis.text.x = element_text(angle = 45,hjust=1)) + theme(plot.margin=unit(c(1,0.5,1,2),"cm")) + scale_x_discrete(breaks=molten$activity[molten$variable=='Importance'], labels=molten$Activity[molten$variable=='Importance'][order(Activity[molten$variable=='Importance'])]) + scale_y_continuous(labels = 0:3, breaks = 0:3, limits = c(0,3)) + xlab('Activity') + ylab('Hours Spent') + labs(title = 'Perceived Importance & Competence\nAssociated with Clerical Duties') + theme(panel.grid.major.x = element_blank()) + geom_vline(xintercept = (maxv[1:length(maxv)%%2!=0]+minv[1:length(minv)%%2==0])/2,col='white') + geom_vline(xintercept = seq(len = 14, by = 2),col = 'white')