The type of graph I want is:
DF <- data.frame(gp=rep(LETTERS[1:5],each=2),
sg=rep(letters[1:2],5),
or=1:10,
orl=0:9,
orh=2:11)
ggplot(DF, aes(x=gp, y=or, colour=sg)) +
geom_pointrange(aes(ymin=orl,ymax=orh),
position=position_dodge(width=0.2)) +
coord_flip()
Exchanging x and y should work, with some modifications. I know
geom_pointrange only works vertically, but the same effect should be
able to be gotten with a combination of geom_segment and geom_point.
ggplot(DF, aes(x=or, y=gp, colour=sg)) +
geom_segment(aes(x=orl, xend=orh, yend=gp)) +
geom_point()
However, no matter what type of position_dodge call I try, I can not get
the points and lines to separate vertically.
ggplot(DF, aes(x=or, y=gp, colour=sg)) +
geom_segment(aes(x=orl, xend=orh, yend=gp),
position=position_dodge(height=0.2)) +
geom_point(position=position_dodge(height=0.2))
ggplot(DF, aes(x=or, y=gp, colour=sg)) +
geom_segment(aes(x=orl, xend=orh, yend=gp),
position=position_dodge(width=0.2)) +
geom_point(position=position_dodge(width=0.2))
In both of those cases, I also get the notes:
ymax not defined: adjusting position using y instead
ymax not defined: adjusting position using y instead
Why can I not dodge vertically along a discrete axis just like I can
dodge horizontally along a discrete axis? Is dodging purely a
horizontal thing? If so, is there any generalization for vertical? It
seems I should be able to dodge (or stack) along any discrete axis, much
as I can jitter along a continuous axis.
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
I think it would be a straightforward generalisation to add vertical
dodging, I've just never written the code. Patches welcome!
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
I might do that. I've poked around in the alignment code before so I
think I could figure it out. A couple of questions, though:
How do you do regression testing on the code? If I'm mucking with
position_dodge, I would want to make sure that it behaves correctly in
all its current uses. How do you do that with graphical output? Do you
already have a testing suite?
I know ggplot2 is undergoing a major rewrite. I've looked in the Github
repositories and saw some of how everything is being rearranged. Is it
worth making changes to the current version, or will that be obsolete
soon? Will the rewrite be ggplot3? Or will it have an identical public API?
Regression testing - what's that? ;)
But no, ggplot2 has really really bad testing at the moment. I'm
trying to do better in the new packages (e.g.
https://github.com/hadley/layers/tree/master/R) but I haven't had much
time lately.
For a new adjustment, the best thing to do would be to build on top of
the layers functions, writing test functions that operate on the
output of the adjustment, not on the final graphics. But layers is
probably so broken that it's difficult to develop on top :(
> I know ggplot2 is undergoing a major rewrite. I've looked in the Github
> repositories and saw some of how everything is being rearranged. Is it worth
> making changes to the current version, or will that be obsolete soon? Will
> the rewrite be ggplot3? Or will it have an identical public API?
The public API will largely be the same, but as you've noticed there
will be huge backend changes (which will hopefully make everything
much simpler). In the interim, probably the best way to proceed is to
focus on the underlying position adjustment algorithm, write unit
tests for it (and for the current adjustments if you really wanted!)
and then do a few basic graphics using base graphics.