Reputation: 2125
The following data shows my projects, time frames, and their phases. I would like to visualize this data using R ggplot() code shown below. However, as we can see below, getting an error while inferring Months from the data. I would like to use the name of Months as x-axis labels. Moreover, I need to print the name of the projects besides the rectangular boxes. Please help me in this. Thank you.
> 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).
Please also see the version of 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)
Upvotes: 2
Views: 422
Reputation: 55350
try converting starts
and ends
to Date
temp$starts <- as.Date(temp$starts)
temp$ends <- as.Date(temp$ends)
If that does not work, you may want to use dput(temp)
and paste that into your question.
Copying + Pasting OP's data, converting to date, then using OP's code
Upvotes: 4