在R中绘制条形图

问题描述 投票:-2回答:1

我对R中条形图的理解非常有限。也许这就是为什么我被困在如此基本的东西上。

所以我有这个数据df_agg

    Planned.start.date  Parent.Application.Release  Actual.Hours    Estimated.Effort
1   2014/08/20 06:00:00 REL0000802                  4               3
2   2014/09/17 06:00:00 REL0000805                  31              21
3   2014/10/15 06:00:00 REL0000808                  102             74
4   2014/11/19 06:00:00 REL0000809                  78              57
5   2014/12/17 06:00:00 REL0000812                  133             67
6   2015/01/22 06:00:00 REL0002534                  12              1

我想做的就是在x轴上绘制带有parent.application.released的条形图,在Y轴上绘制Actual Hours或Estimated.effort

我尝试这样做的方式是

barplot(Df_agg$Actual.Hours,names=Df_agg$parent.application.release)

它给我一个错误:

'height' must be a vector or a matrix

我想尝试as.vector,这也行不通。为什么会发生这种情况?以及我如何根据需要绘制图表

PS:另外我想通过planned.start.date安排条形图中的区间顺序,并且可能在y轴上并排显示同一条图中的actual.hours和estimated.effort但是现在我我只是专注于绘制一个简单的条形图。

但是,如果你能分享我如何实现上述想法,我将非常感激

r
1个回答
2
投票

试试ggplot2包,

require("ggplot2")
qplot(x = reorder(Parent.Application.Release,Actual.Hours), y = Actual.Hours, data=df_agg, geom="bar", stat="identity", xlab="Parent Application Release", ylab = "Actual Hours", main = "My bar plot")  + theme(legend.position="none")

© www.soinside.com 2019 - 2024. All rights reserved.