r - R中多列的条形图

标签 r charts bar-chart

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)
我想使用基本图形,但如果无法完成,那么我不反对在必要时安装软件包。

最佳答案

plot

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/

相关文章:

删除ggplot2 geom_bar中条形之间的空间

r - 如何在 R 中合并两个数据帧后打印新列

r - 在 R 中为 networkD3 包创建列表时遇到问题

r - 使用 R 中的 jpeg 包检测无效或损坏的 jpg 文件

css - JAVAFX 8 图表 : get style of existing plotted series

javascript - 条形图 D3.js 错误 : Invalid value for <rect> attribute

r - 在 ggplot2 r 中添加轴刻度和标签

javascript - D3.js 鼠标悬停和焦点 + 上下文问题

javascript - 谷歌时间轴图表到图像

android - 使用 achartengine 的条形图