Hi Roey,
It's not clear what you expect should happen when you dodge the
labels. Can you give a reproducible example and more clearly state
what result you're looking for?
Also, I've changed the subject line as this seems to be different
issue than the OP described.
Best,
Ista
On Wed, Jun 13, 2012 at 5:57 AM, Roey Angel <
an...@mpi-marburg.mpg.de> wrote:
> Hi,
> I also have a problem with position="dodge" in geom_text in ggplot0.9
> (though I don't know if it worked in previous versions).
> The code is bit complicated to give a minimal example, but I confirmed the
> problem on other codes as well.
> the line is:
> geom_text(aes(x= X, y= Y, label = name), data = coords, position = "dodge")
>
> which gives the message:
> ymax not defined: adjusting position using y instead
>
> and the dodging doesn't take effect.
>
> I tried also:
> position = position_dodge(width=1))
>
> position = position_dodge(width=1, height=1))
> or as suggested here:
> position=position_dodge(0.9)
>
>
> But none of them worked (actually adding a numeric value granted me with
> another warning message):
> Warning message:
> position_dodge requires non-overlapping x intervals
>
> Any suggestions?
>
> Thanks in advance
> Roey
>
>
>
> On Sunday, March 11, 2012 8:26:35 AM UTC+1, winston wrote:
>>
>> I couldn't get your code to dodge the text in 0.8.9, until I changed the
>> code from position="dodge" to position=position_dodge(0.9). This is probably
>> because text objects are treated like points, and don't have a real
>> width/height.
>>
>> After making that change to your code, I tracked down where the change in
>> behavior happened... it looks like it happened with this commit:
>>
https://github.com/hadley/ggplot2/commit/ac91fe4
>>
>> I believe the change is actually a feature, not a bug. :)
>>
>> Typically, a variable is mapped to fill or colour, and each level of that
>> variable indicates a separate group. (Actually, all the discrete variables
>> are crossed to form the groups, but that's not important here.) Next, all
>> objects that have the same x position, but are in different groups, get
>> dodged.
>>
>> With the geom_bar, 'income' was mapped to 'fill', so each level of income
>> was a separate group; since each of the bars is in a different group, they
>> are dodged. With the geom_text, there was no grouping variable, and so all
>> of the text at each x was in a single group. Since the text objects were all
>> in one group, they should NOT have been dodged, but the dodging happened
>> anyway. This is because the old code made some erroneous assumptions about
>> the structure of the data.
>>
>> To make it work now, you have to specify the grouping for the text, which
>> can be done with 'aes(group=income)'. (You could also use 'colour=income',
>> but you probably don't want to change the text color.)
>>
>> This code should do the trick:
>>
>> library(ggplot2)
>> set.seed (66)
>> income <- rep(c("high","medium","low"), 5)
>> variable <- rep(c("USA","Switzerland","Spain","Greece","Japan"),3)
>> mean.value <- rnorm (15,5,2)
>> m.data <- data.frame (income,variable,mean.value)
>>
>> pl <- ggplot(data=m.data, aes(x=variable, y=mean.value, ymax=10))
>> pl <- pl + geom_bar(aes(fill=income),position=position_dodge(0.9))
>> pl <- pl + geom_text(aes(group=income, label=round(mean.value, 2)),
>> position=position_dodge(0.9), hjust=-0.5)
>> pl <- pl + coord_flip()
>> pl
>>
>>
>> -Winston
>>
>> On Sat, Mar 10, 2012 at 6:12 PM, igreg <
zoor...@gmx.net> wrote:
>>>
>>> hi ggploters
>>>
>>> please have a look at my code (worked in 0.89 but not anymore in 0.90)
>>>
>>> library (ggplot2)
>>> library (reshape)
>>> library (scales)
>>>
>>> set.seed (66)
>>> income <- rep(c("high","medium","low"), 5)
>>> variable <- rep(c("USA","Switzerland","Spain","Greece","Japan"),3)
>>> mean.value <- rnorm (15,5,2)
>>> m.data <- data.frame (income,variable,mean.value)
>>>
>>> pl <- ggplot(data=m.data, aes(x=variable, y=mean.value,ymax=10))
>>> pl <- pl + geom_bar(aes(fill=income),position="dodge")
>>> pl <- pl + geom_text(aes(label=round(mean.value,
>>> 2)),position="dodge",hjust=-0.5)
>>> pl <- pl + coord_flip()
>>> pl
>>>
>>> the numbers in the plot are not in dodge position like the bars. they
>>> appear all in the same line.
>>>
>>> is it my system or is it a bug in 0.9?
>>>
>>> thanks for your help!
>>>
>>> greg
>>>
>>> R version 2.14.2 (2012-02-29)
>>> Platform: x86_64-pc-mingw32/x64 (64-bit)
>>>
>>> locale:
>>> [1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.
>>> 1252
>>> [3] LC_MONETARY=German_Switzerland.1252
>>> LC_NUMERIC=C
>>> [5] LC_TIME=German_Switzerland.1252
>>>
>>> attached base packages:
>>> [1] stats graphics grDevices utils datasets methods
>>> base
>>>
>>> other attached packages:
>>> [1] ggplot2_0.9.0 scales_0.2.0 reshape_0.8.4 plyr_1.7.1
>>>
>>> loaded via a namespace (and not attached):
>>> [1] colorspace_1.1-1 dichromat_1.2-4 digest_0.5.1
>>> grid_2.14.2
>>> [5] MASS_7.3-17 memoise_0.1 munsell_0.3
>>> proto_0.3-9.2
>>> [9] RColorBrewer_1.0-5 reshape2_1.2.1 stringr_0.6
>>> tools_2.14.2
>>>
>>> --
>>> 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:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2