R 新手并试图找出条形图。
我正在尝试在 R 中创建一个条形图,它显示来自按第三列分组的 2 列的数据。
数据帧名称:SprintTotalHours
包含数据的列:
OriginalEstimate,TimeSpent,Sprint
178,471.5,16.6.1
210,226,16.6.2
240,195,16.6.3
我想要一个条形图,在每个 sprint 的 OriginalEstimate
旁边显示 TimeSpent
。我试过这个,但我没有得到我想要的:
colours = c("red","blue")
barplot(as.matrix(SprintTotalHours),main='Hours By Sprint',ylab='Hours', xlab='Sprint' ,beside = TRUE, col=colours)
abline(h=200)
我想使用基本图形,但如果无法完成,那么我不反对在必要时安装软件包。
最佳答案
cols <- c('red','blue');
ylim <- c(0,max(SprintTotalHours[c('OriginalEstimate','TimeSpent')])*1.8);
par(lwd=6);
barplot(
t(SprintTotalHours[c('OriginalEstimate','TimeSpent')]),
beside=T,
ylim=ylim,
border=cols,
col='white',
names.arg=SprintTotalHours$Sprint,
xlab='Sprint',
ylab='Hours',
legend.text=c('Estimated','TimeSpent'),
args.legend=list(text.col=cols,col=cols,border=cols,bty='n')
);
box();
数据
SprintTotalHours <- data.frame(OriginalEstimate=c(178L,210L,240L),TimeSpent=c(471.5,226,
195),Sprint=c('16.6.1','16.6.2','16.6.3'),stringsAsFactors=F);
关于r - R中多列的条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37931327/