Adding arrow to end of x-axis line

1,865 views
Skip to first unread message

Robin Wilson

unread,
Aug 21, 2010, 8:16:10 PM8/21/10
to ggplot2
Hi,

I'm creating a page of small line graphs to show the way in which
various variables change over time. I don't need to have the actual
numbers for the time shown on the x-axis, but I need to show that the
values are increasing from left to right. In many plots I've seen this
is shown by using an arrow on the right-hand end of the x-axis.

Is there a way to do this in ggplot2?

Regards,

Robin

baptiste auguie

unread,
Aug 22, 2010, 5:58:57 AM8/22/10
to Robin Wilson, ggplot2
Hi,

You could add an arrow at the bottom of the plot,

library(ggplot2)

p <- qplot(1,1)

p + theme_bw() +
annotate("segment", x=-Inf,xend=Inf,y=-Inf,yend=-Inf,arrow=arrow())

However there's a problem of clipping to the plotting region. I guess
it should be possible to navigate to this viewport and change the
clipping to FALSE but I forget how.

HTH a little,

baptiste

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Robin Wilson

unread,
Aug 22, 2010, 6:31:47 AM8/22/10
to ggplot2
Hi,

Thanks for the suggestion. However, that doesn't seem to change
anything on my plot. I've tried running your code by itself, and that
doesn't seem to do anything either.

Does anyone have any other ideas about this? I've tried reading about
the viewpoints mentioned by Baptiste, but they seem to confuse me! I'd
wouldn't have thought it was that unusual to want an arrow on the axis
- but maybe I'm wrong!

Regards,

Robin

Brandon Hurr

unread,
Aug 22, 2010, 7:38:29 AM8/22/10
to Robin Wilson, ggplot2
Seems quite clear that there is an arrow in the bottom right on the axes. Perhaps easier to see if you stick it to y=0 and change the limits of the scale...

library(ggplot2)

p <- qplot(1,1)

p  + theme_bw() +
annotate("segment", x=-Inf,xend=Inf,y=0,yend=0,arrow=arrow())+
scale_y_continuous(limits=c(-0.5, 1))
arrow.png
Reply all
Reply to author
Forward
0 new messages