R中多列的条形图 [英] Barplot with multiple columns in R

查看:25
本文介绍了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.

数据帧名称:SprintTotalHours

包含数据的列:

OriginalEstimate,TimeSpent,Sprint
178,471.5,16.6.1
210,226,16.6.2
240,195,16.6.3

我想要一个条形图,在每个冲刺的 TimeSpent 旁边显示 OriginalEstimate.我试过了,但我没有得到我想要的:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆