[R] ggplot: dodge positions
John Kane
jrkrideau at inbox.com
Mon Jul 2 15:20:43 CEST 2012
I don't think I was clear. Sorry. What I was refering to was the
ggplot(ddf, aes(x, y, colour=grp)) + geom_boxplot() + geom_point(aes(ymax=max(y)),
position = position_dodge(width=.75))
which is giving me http://www.mediafire.com/i/?fdurpq6e6l8cu35 which was what I though you want.
I have no idea how the x axis points on the boxplot are determined. It may be relatively clear in the code but I don't really have the knowledge to ferret it out.
Sorry that I cannot be of more help.
John Kane
Kingston ON Canada
> -----Original Message-----
> From: thorn.thaler at rdls.nestle.com
> Sent: Mon, 2 Jul 2012 15:10:33 +0200
> To: jrkrideau at inbox.com, r-help at r-project.org
> Subject: RE: [R] ggplot: dodge positions
>
> I guess it works with ggplot but not with ggplot2. I'm using only the
> latter but had a typo in my first post. So the code (which does not do
> what I want) is:
>
> library(ggplot2)
> ddf <- data.frame(x=factor(rep(LETTERS[1:4], each=30)), y =
> runif(120,0,10), grp = factor(rep(rep(1:3, 10), 4)))
> ggplot(ddf, aes(x, y, colour=grp)) + geom_boxplot() + geom_point()
>
> Thinking of it, I would need to find out which offset ggplot uses to
> dodge the nested factors. If I knew the exact quantity, I could do
> something like
>
> geom_point(aes(x = offset.used.by.geom_boxplot))
>
> So how are the exact positions on the x-axis for geom_boxplot determined?
> Any ideas?
>
> Thanks for the help, anyways.
>
> KR,
>
> -Thorn
>
>
>> -----Original Message-----
>> From: John Kane [mailto:jrkrideau at inbox.com]
>> Sent: Montag, 2. Juli 2012 15:04
>> To: Thaler,Thorn,LAUSANNE,Applied Mathematics; r-help at r-project.org
>> Subject: RE: [R] ggplot: dodge positions
>>
>> Can you expand a bit on what is wrong with the dodge option? From what
>> I see it looks lovely witht the points exactly lined with the boxplots
>> for each group but perhaps I don't understand exactly what you want .
>>
>>
>>
>> John Kane
>> Kingston ON Canada
>>
>>
>>> -----Original Message-----
>>> From: thorn.thaler at rdls.nestle.com
>>> Sent: Mon, 2 Jul 2012 11:43:03 +0200
>>> To: r-help at r-project.org
>>> Subject: [R] ggplot: dodge positions
>>>
>>> Dear all,
>>>
>>> I want to get a series of boxplots (grouped by two factors) and I
>> want to
>>> overlay the original observations and the following code does almost
>> what
>>> I want:
>>>
>>> library(ggplot)
>>> ddf <- data.frame(x=factor(rep(LETTERS[1:4], each=30)), y =
>>> runif(120,0,10), grp = factor(rep(rep(1:3, 10), 4)))
>>> ggplot(ddf, aes(x, y, colour=grp)) + geom_boxplot() + geom_point()
>>>
>>> Yet the position of the points and the position of the boxes on the
>>> x-axis is not the same. I would like that the points are shifted
>>> accordingly, such that they line up with the boxplots. I tried
>>> position_dodge:
>>>
>>> ggplot(ddf, aes(x, y, colour=grp)) + geom_boxplot() +
>>> geom_point(aes(ymax=max(y)), position = position_dodge(width=.75))
>>>
>>> but that did not really help, as all points are now dodged and I just
>>> want to have a fixed offset for each subgroup of points such that the
>>> boxplot and the points are aligned. Any ideas?
>>>
>>>
>>> Kind Regards,
>>>
>>> Thorn Thaler
>>> Mathematician
>>>
>>> Applied Mathematics
>>> Nestec Ltd,
>>> Nestlé Research Center
>>> PO Box 44
>>> CH-1000 Lausanne 26
>>> Phone: +41 21 785 8220
>>> Fax: +41 21 785 9486
>>
>> ____________________________________________________________
>> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
>> http://www.inbox.com/smileys
>> Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™
>> and most webmails
>>
>>
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails
More information about the R-help
mailing list