> opts(title = "Ugh, what's with all the inappropriatelevels?")
>
> p.bar
>
> # As you can see it's almost there, but for some reason it's put all the
> levels
> # in for each category, we didn't have that problem in 'p.dot'
I think the problem is that facet_grid sets the scales for each row
and / or column in the facet, not for individual "cells" in the facet.
And then it gets confused by coord_flip, and doesn't realize that the
rows and columns have switched.
There is already a bug report open on this issue
(https://github.com/hadley/ggplot2/issues/95) so hopefully it will be
fixed soon. In the meantime the closest I can get is
ggplot(dat, aes(x = item, y = proportion)) +
geom_bar() +
facet_wrap(~ type, scales = "free", ncol = 1) +
coord_flip()
HTH,
Ista
> --
> 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
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
If you really already have pre-summarized data, here is another work around:
GeomHbar <- proto(Geom, {
default_stat <- function(.) StatIdentity
default_pos <- function(.) PositionIdentity
default_aes <- function(.) aes(colour=NA, fill="grey20", size=0.5,
linetype=1, weight = 1, alpha = 1)
required_aes <- c("x", "y")
reparameterise <- function(., df, params) {
df$width <- df$width %||%
params$width %||% (resolution(df$y, FALSE) * 0.9)
transform(df,
xmin = pmin(x, 0), xmax = pmax(x, 0),
ymin = y - width / 2, ymax = y + width / 2, width = NULL
)
}
draw_groups <- function(., data, scales, coordinates, ...) {
GeomRect$draw_groups(data, scales, coordinates, ...)
}
# Documentation -----------------------------------------------
objname <- "hbar"
desc <- "Bars, rectangles with bases on y-axis"
guide_geom <- function(.) "polygon"
icon <- function(.) {
rectGrob(c(0.3, 0.7), c(0.4, 0.8), height=c(0.4, 0.8), width=0.3,
vjust=1, gp=gpar(fill="grey20", col=NA))
}
})
geom_hbar <- GeomHbar$build_accessor()
p.hbar <- ggplot(dat, aes(x = proportion, y = item)) +
geom_hbar() +
facet_grid(type ~ ., scales = "free_y", space = "free") +
opts(title = "Good, actual horizontal bars")
p.hbar
Note that geom_hbar is not nearly as general as geom_bar; for one thing
its default stat is identity, not bin. There isn't a stat which bins
along the y axis (although you could write one), so if you try to change
the stat to bin, I don't really know what would happen. Basically, I
just took geom_bar, flipped the x and y in the reparameterise function,
and changed the default stacking and stat.
>>> To post: email ggplot2-/JYPxA39Uh5...@public.gmane.org
>>> To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh5...@public.gmane.org
>>> More options: http://groups.google.com/group/ggplot2
>>>
>>
>>
>>
>> --
>> Ista Zahn
>> Graduate student
>> University of Rochester
>> Department of Clinical and Social Psychology
>> http://yourpsyche.org
>>
>
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
On 9 August 2011 13:14, Ista Zahn<izahn-7lguHJXwfyo6QsK68V2XfZVzexx5G7l...@public.gmane.org> wrote:
Hi Stuart,
On Tue, Aug 9, 2011 at 5:09 AM, Stuart Sharples
To post: email ggplot2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh5TLH3M...@public.gmane.org
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
--
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+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2
I did it from the source code, not from within R. (I got it from the
github website, although I do have a copy of the repository on my
machine so I could have gotten it from there.) Since ggplot uses
proto[*], I find it hard to track down appropriate source from within R.
[*] A lot of the guts are being re-written for ggplot2-0.9.0, including
the dependence on proto. That also means that this code for a
horizontal bar won't work with 0.9.0 when it is released.
> Thanks again!
>
> Stu
>
>
> On 9 August 2011 17:25, Brian Diggs <dig...@ohsu.edu
> <mailto:izahn-7lguHJXwfyo6Q...@public.gmane.org>> wrote:
>
> Hi Stuart,
>
> On Tue, Aug 9, 2011 at 5:09 AM, Stuart Sharples
> <stuart.sharples- Re5JQEeQqe8AvxtiuMwx3w@public. gmane.org
> <mailto:stuart.sharples-Re5...@public.gmane.org>>
> <https://github.com/hadley/ggplot2/issues/95>) so hopefully
> pushViewport(viewport(layout. pos.col = 2))
> print(p.bar, newpage = FALSE)
> popViewport()
> pushViewport(viewport(layout. pos.col = 3))
> print(p.bar.vert, newpage = FALSE)
> popViewport()
>
>
> # P.S. With 'p.dot' there also seems to be something
> wrong; there's white
> space
> # between the tick marks of 'Tomato' and Lime' and
> the plotting area
>
> # What I'm using:
> # Ubuntu 10.04, R version 2.13.1, ggplot2 version 0.8.9
>
> --
> 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 ggplot2-/JYPxA39Uh5TLH3MbocFFw
> @public.gmane.org
> <mailto:JYPxA39Uh5...@public.gmane.org>
> To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh
> 5TLH3M...@public.gmane.org
> <mailto:JYPxA39Uh5...@public.gmane.org>
>
> More options: http://groups.google.com/ group/ggplot2
> <http://groups.google.com/group/ggplot2>
>
>
>
>
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
>
>
>
>
> --
> Brian S. Diggs, PhD
> Senior Research Associate, Department of Surgery
> Oregon Health & Science University
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+unsubscribe@ googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> More options: http://groups.google.com/ group/ggplot2
> <http://groups.google.com/group/ggplot2>
Here's another approach using geom_segment():
ggplot(dat, aes(x = proportion, y = item)) +
geom_segment(aes(xend = 0, yend = item), size = 10) +
facet_grid(type ~ ., scales = 'free_y', space = 'free')
All this does is replace geom_point() with the equivalent code in
geom_segment(). Hopefully this is a bit more robust wrt the upcoming
changes in ggplot2.
HTH,
Dennis
>>> Zahn<izahn-7lguHJXwfyo6Q...@public.gmane.org> wrote:
>>>
>>>> Hi Stuart,
>>>>
>>>> On Tue, Aug 9, 2011 at 5:09 AM, Stuart Sharples
>>>> <stuart.sharples-Re5...@public.gmane.org> wrote:
>>>>> To post: email ggplot2-/JYPxA39Uh5...@public.gmane.org
>>>>> To unsubscribe: email
>>>>> ggplot2+unsubscribe-/JYPxA39Uh5...@public.gmane.org
>>>>> More options: http://groups.google.com/group/ggplot2
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Ista Zahn
>>>> Graduate student
>>>> University of Rochester
>>>> Department of Clinical and Social Psychology
>>>> http://yourpsyche.org
>>>>
>>>
>>
>>
>> --
>> Brian S. Diggs, PhD
>> Senior Research Associate, Department of Surgery
>> Oregon Health & Science University
>>
>> --
>> 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
>
> --
> 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