reversing tick direction with annotation_logticks

808 views
Skip to first unread message

Ben Bolker

unread,
Mar 8, 2013, 8:50:33 PM3/8/13
to ggplot2, Karen Cogliati
I'm trying to get logarithmic ticks as produced by
annotation_logticks, but with the ticks on the outside rather than the
inside of the frame. Making the tick lengths negative, which seems to
work fine for regular ticks, fails for annotation_logticks. I've dug
around a bit within the ggplot2:::GeomLogticks$draw_groups() function,
but haven't been able to figure out my results -- one of the medium
ticks remains, pointing inward, and the short and long ticks disappear ...

If anyone is interested in digging into this,
debug(ggplot2:::GeomLogticks$draw_groups) seems like a good starting point.

Any ideas welcome.

thanks
Ben Bolker

=========
library("ggplot2")
library("grid")

## regular plot, ticks outside
plot <- qplot(1:10,1:10)
plot
theme_set(theme_bw())
plot + theme(axis.ticks.length=unit(-0.15,"cm"),
axis.ticks.margin=unit(0.25,"cm"))


## log-scale plot
(lplot <- plot+scale_y_log10())

## regular annotation: ticks inside
lplot+annotation_logticks(sides="l")

## attempt to put ticks outside
lplot+annotation_logticks(sides="l",
short=unit(-1,"mm"),
medium=unit(-2,"mm"),
long=unit(-3,"mm"))


)

sessionInfo()
R Under development (unstable) (2012-12-14 r61321)
Platform: i686-pc-linux-gnu (32-bit)

[snip]

other attached packages:
[1] ggplot2_0.9.3.1

loaded via a namespace (and not attached):
[1] colorspace_1.2-0 dichromat_1.2-4 digest_0.6.0
gtable_0.1.2
[5] labeling_0.2 MASS_7.3-23 munsell_0.4 plyr_1.8

[9] proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2
scales_0.2.3
[13] stringr_0.6.2

Ben Bolker

unread,
Mar 9, 2013, 5:13:50 PM3/9/13
to baptiste auguie, ggplot2
On 13-03-08 09:16 PM, baptiste auguie wrote:
> otoh you can edit the gtable to turn the vIewport clipping off
>
> sent from my phone

I'm sorry: this might be a good direction but it's a little too
telegraphic for me.

I can get as far as

p3 <- ggplotGrob(p2)
p4 <- p3$grobs[[which(p3$layout$name=="axis-l")]]

str(p4)

And I've looked at

https://github.com/hadley/ggplot2/wiki/Editing-raw-grid-objects-from-a-ggplot

but I don't see where to edit ... the only bits of the structure called
"clip" are either FALSE or "off" ...

sorry -- more help ???

Ben Bolker
>
>> On 9/03/2013 2:50 PM, "Ben Bolker" <bbo...@gmail.com
>> --
>> --
>> You received this message because you are subscribed to the ggplot2
>> mailing list.
>> Please provide a reproducible example:
>> https://github.com/hadley/devtools/wiki/Reproducibility
>>
>> To post: email ggp...@googlegroups.com <mailto:ggp...@googlegroups.com>
>> To unsubscribe: email ggplot2+u...@googlegroups.com
>> <mailto:ggplot2%2Bunsu...@googlegroups.com>
>> More options: http://groups.google.com/group/ggplot2
>>
>> ---
>> You received this message because you are subscribed to the Google
>> Groups "ggplot2" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to ggplot2+u...@googlegroups.com
>> <mailto:ggplot2%2Bunsu...@googlegroups.com>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>

baptiste auguie

unread,
Mar 9, 2013, 5:25:16 PM3/9/13
to Ben Bolker, ggplot2
Here's a translation of my random mumbling from yesterday,

library(ggplot2)

p <- qplot(1:10, 1:10)  + 
  annotation_logticks(long=unit(-2, "mm"))

g <- ggplot_gtable(ggplot_build(p))

g$layout$clip[g$layout$name == "panel"] <- "off"
grid.draw(g)

Obvious downside, turning clipping off can also have undesirable effects...

HTH,

baptiste

Ben Bolker

unread,
Mar 9, 2013, 5:47:36 PM3/9/13
to baptiste auguie, ggplot2
Thanks!

This in combination with a small hack of ggplot2:::GeomLogticks (I
added a line

yticks <- with(yticks,yticks[value > base^scales$y.range[1] &
value< base^scales$y.range[2],])

to remove the superfluous ticks outside the range of y, which show up
when clipping is turned off)

seems to be doing what I need.

Ben Bolker



On 13-03-09 05:25 PM, baptiste auguie wrote:
> Here's a translation of my random mumbling from yesterday,
>
> library(ggplot2)
>
> p <- qplot(1:10, 1:10) +
> annotation_logticks(long=unit(-2, "mm"))
>
> g <- ggplot_gtable(ggplot_build(p))
>
> g$layout$clip[g$layout$name == "panel"] <- "off"
> grid.draw(g)
>
> Obvious downside, turning clipping off can also have undesirable effects...
>
> HTH,
>
> baptiste
>
> On 10 March 2013 11:13, Ben Bolker <bbo...@gmail.com
> <mailto:bbo...@gmail.com>> wrote:
>
> On 13-03-08 09:16 PM, baptiste auguie wrote:
> > otoh you can edit the gtable to turn the vIewport clipping off
> >
> > sent from my phone
>
> I'm sorry: this might be a good direction but it's a little too
> telegraphic for me.
>
> I can get as far as
>
> p3 <- ggplotGrob(p2)
> p4 <- p3$grobs[[which(p3$layout$name=="axis-l")]]
>
> str(p4)
>
> And I've looked at
>
> https://github.com/hadley/ggplot2/wiki/Editing-raw-grid-objects-from-a-ggplot
>
> but I don't see where to edit ... the only bits of the structure called
> "clip" are either FALSE or "off" ...
>
> sorry -- more help ???
>
> Ben Bolker
> >
> >> On 9/03/2013 2:50 PM, "Ben Bolker" <bbo...@gmail.com
> <mailto:bbo...@gmail.com>
> <mailto:ggp...@googlegroups.com> <mailto:ggp...@googlegroups.com
> >> <mailto:ggplot2%2Bunsu...@googlegroups.com
> <mailto:ggplot2%252Buns...@googlegroups.com>>
> >> More options: http://groups.google.com/group/ggplot2
> >>
> >> ---
> >> You received this message because you are subscribed to the Google
> >> Groups "ggplot2" group.
> >> To unsubscribe from this group and stop receiving emails from it,
> send
> >> an email to ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> >> <mailto:ggplot2%2Bunsu...@googlegroups.com
> <mailto:ggplot2%252Buns...@googlegroups.com>>.
Reply all
Reply to author
Forward
0 new messages