以下数据显示了我的项目、时间框架及其阶段。我想使用如下所示的 R ggplot() 代码可视化这些数据。但是,正如我们在下面看到的,在从数据中推断月份时出现错误。我想使用 Months 的名称作为 x 轴标签。此外,除了矩形框外,我还需要打印项目的名称。请帮助我。谢谢你。
> temp
projects starts ends order Phase
A 2013-02-15 2013-03-15 1 Research
A 2013-03-16 2013-04-15 1 Prototype
B 2013-04-07 2013-04-30 2 Research
B 2013-05-01 2013-08-30 2 Prototype
C 2013-05-01 2013-07-30 3 Research
D 2013-05-01 2013-07-30 4 Research
> a = ggplot(temp, aes(xmin = starts, xmax = ends, ymin = order, ymax = order+0.5)) + geom_rect(aes(fill=Phase), color="black") + theme_bw()
> b = a + geom_text(aes(x= starts + (ends-starts)/2 ,y=order+0.25, label=projects))
> b
Error in unit(x, default.units) : 'x' and 'units' must have length > 0
In addition: Warning messages:
1: In Ops.factor(ends, starts) : - not meaningful for factors
2: In Ops.factor(starts, (ends - starts)/2) : + not meaningful for factors
3: Removed 6 rows containing missing values (geom_text).
另请参阅 R 的版本。
> version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 2
minor 15.2
year 2012
month 10
day 26
svn rev 61015
language R
version.string R version 2.15.2 (2012-10-26)