Try this. You also had some typos on the names and weren't using the
dataframe correctly.
x <- read.table(textConnection(" Company Pt
Pri Pub
1 A WO520 8/5/09 2/11/10
2 B WO893 7/30/03 2/24/05
3 A WO258 12/8/08 6/17/10
4 C WO248 1/13/09 9/2/10"),
header = TRUE, as.is = TRUE)
closeAllConnections()
x$Pri <- as.Date(x$Pri, format = '%m/%d/%y')
x$Pub <- as.Date(x$Pub, format = '%m/%d/%y')
y <- seq(0,0.5*(length(x$Company)-1),0.5)
h <- 0.1
plot(range(x$Pri, x$Pub), c(0, nrow(x) - 1), type = 'n')
rect(x$Pri, y-h, x$Pub, y+h, col=c("light
blue","pink","yellow","red"))
On Sat, Oct 9, 2010 at 3:10 PM, Eric Hu <Eric.Hu at gilead.com>
wrote:> Hi,
> I am trying to use rect (R2.11) to plot a set of data as following
>
>
> ?> data
> ?Company ? ? ? ?Pt ? ? ? ? ? ? ? ? ?Pri ? ? ? ? ? ? ? ? ?Pub
> 1 ? ?A ? ? ? ? ? ?WO520 ? ? ? ? ?8/5/09 ? ? ? ? ?2/11/10
> 2 ? ?B ? ? ? ? ? ?WO893 ? ? ? ? 7/30/03 ? ? ? ? ?2/24/05
> 3 ? ?A ? ? ? ? ? ?WO258 ? ? ? ? 12/8/08 ? ? ? ? ?6/17/10
> 4 ? ?C ? ? ? ? ? WO248 ? ? ? ? 1/13/09 ? ? ? ? ? 9/2/10
>
>
> pri<- strptime(pri,"%m/%d/%y")
> pub <- strptime(pub,"%m/%d/%y")
>
> plot.new()
> plot.window(xlim=c(min(pri,pub),max(pri,pub)),ylim=c(0,length(company)-1))
> %y <- seq(0,0.5*(length(company)-1),0.5)
> %h <- 0.1
> %rect(pri, y-h, pub, y+h, col=c("light
blue","pink","yellow","red"))
>
> Neither xlim nor rect/boxplot recognizes pri/pub with date format. I wonder
if there is a good way to deal with the date ploting so the x-axis can reflect
the actual time range.
>
> Thank you,
> Eric
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?