R中具有多列的条形图 [英] Barplot with multiple columns in R
本文介绍了R中具有多列的条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
R的新手,并试图找出该条形图。
我试图在R中创建一个条形图,以显示来自按第三列分组的2列的数据。
New to R and trying to figure out the barplot.
I am trying to create a barplot in R that displays data from 2 columns that are grouped by a third column.
DataFrame名称: SprintTotalHours
DataFrame Name: SprintTotalHours
包含数据的列:
OriginalEstimate,TimeSpent,Sprint
178,471.5,16.6.1
210,226,16.6.2
240,195,16.6.3
我想要一个在 TimeSpent $ c旁边显示
OriginalEstimate
的条形图$ c>每个冲刺。
我尝试了这个,但没有得到想要的东西:
I want a barplot that shows the OriginalEstimate
next to the TimeSpent
for each sprint.
I tried this but I am not getting what I want:
colours = c("red","blue")
barplot(as.matrix(SprintTotalHours),main='Hours By Sprint',ylab='Hours', xlab='Sprint' ,beside = TRUE, col=colours)
abline(h=200)
我想使用基本图形,但是如果无法完成,我不反对在必要时安装软件包。
I would like to use base graphics but if it can't be done then I am not opposed to installing a package if necessary.
推荐答案
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中具有多列的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文