2
$\begingroup$

I'm using the following code to insert vertical lines in a timeseries plot:

abline(v=as.Date("2007-09-19"),col="red",lty=2)
abline(v=as.Date("2008-03-10"),col="red",lty=2)
abline(v=as.Date("2008-04-28"),col="red",lty=2)
abline(v=as.Date("2009-08-07"),col="red",lty=2)

But I would rather prefer a small triangle pointing up in the bottom axis, along with a label. Hints?

$\endgroup$

3 Answers 3

3
$\begingroup$

There's a variety of ways. You could use a pch = '^' and put that near the bottom or look up an arrow symbol character. Also you could just do what you're doing with the arrows() command and draw short arrows instead of abline(). With arrows you would need to specify both ends instead of just the horizontal position.. e.g.

arrows(as.Date("2009-08-07"),0, as.Date("2009-08-07"), 0.5, col="red",lty=2)
$\endgroup$
2
  • $\begingroup$ Thnks! Any way to add a small, filled triangle? $\endgroup$ Nov 13, 2010 at 3:52
  • $\begingroup$ @Hugo See my response with pch. $\endgroup$
    – chl
    Nov 13, 2010 at 9:19
4
$\begingroup$

I prefer to use dedicated symbol for that purpose. For example, use points() with pch=17 (filled triangle) like in the example below:

dd <- dotplot(m~i|p,data=res.EQ.long,subset=i %in% eq5d.items.names[1:5],
              ylab="Score",ylim=c(0.5,3.5),  
              scales=list(x=list(rot=45,at=1:5,
                          labels=eq5d.items.names[1:5],cex=c(.8,.8))),
              main="EQ-5D",
              panel=function(x,y,subscripts,...){
              panel.dotplot(x,y,...)
              panel.lines(x=c(1,5),y=3,lwd=1.5, col="gray50")
              panel.segments(x0=c(1,3,5),y0=rep(2.95,3),
                             x1=c(1,3,5),y1=rep(3.05,5),
                             lwd=1.5, col="gray50")
              panel.text(x=c(1,3,5),y=3,c(0,50,100),cex=.6,pos=3)
              panel.text(x=3,y=3.2,"Health State",cex=.6,pos=3)
              panel.points(x=(4*ref[packet.number()])/100+1,y=2.9,
                           pch=17)
              panel.points(x=1:5,y=res.EQ2[1:5,packet.number()],
                           col="red",pch=19,cex=.6)
              },
              key=list(text=list(c("Mean","Median")),x=0.7,y=0.9,
                       lines=list(col=c("blue","red"),type="p",
                       pch=19,cex=.8)))
print(dd)

alt text

The complete list of symbols can be obtained with show.pch() from the Hmisc package.

$\endgroup$
0
$\begingroup$

You could manually construct the triangles using the 'polygon' command. There might be a nice way to automate the construction of these but depending on how many you want to make it probably wouldn't be too bad to figure out the coordinates by hand.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.