Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puzzled for annotation that contain duplicate contents #6

Closed
powerinformatics opened this issue Apr 14, 2017 · 2 comments
Closed

Puzzled for annotation that contain duplicate contents #6

powerinformatics opened this issue Apr 14, 2017 · 2 comments

Comments

@powerinformatics
Copy link

Hi Constantin,
The package you provide is exceedingly useful.
But I'm troubled by the function aes(annotation=). The annotation would be merged and drawn on the midpoint coordinate, when the annotation contain duplicate contents.
You can try this code which comes from the site https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html.
After I modified the content of annotation, the strange result emerged.
geom_signif(stat="identity", data=data.frame(x=c(0.875, 1.875), xend=c(1.125, 2.125), y=c(5.8, 8.5), annotation=c("**", "**")), aes(x=x,xend=xend, y=y, yend=y, annotation=annotation))
Waitting for your solution.

@const-ae
Copy link
Owner

Hi,
the issue you raise is very puzzling indeed...
To quickly fix the problem, just define the group in aes(x=x,xend=xend, y=y, yend=y, annotation=annotation, group=c(1,2)):

ggplot(dat, aes(Group, Value)) +
  geom_bar(aes(fill = Sub), stat="identity", position="dodge", width=.5) +
  geom_signif(comparisons=list(c("S1", "S2")), annotations="***",
              y_position = 9.3, tip_length = 0, vjust=0.4) +
  geom_signif(stat="identity",
              data=data.frame(x=c(0.875, 1.875), xend=c(1.125, 2.125),
                              y=c(5.8, 8.5), annotation=c("**", "**")),
              aes(x=x,xend=xend, y=y, yend=y, annotation=annotation, group=c(1,2))) +
  scale_fill_manual(values = c("grey80", "grey20"))

image

The problem is that currently the data is separated by annotation into different groups and if the annotation is identical for some rows it is assumed that it's just a more complex definition of the bracket.

I will see if I can find a better pattern to avoid confusion or I will update the documentation in the next release.

const-ae added a commit that referenced this issue Apr 14, 2017
Identical annotations lead to weird behavior if stat="identity" is used. The problem is that the data is grouped by annotation and identical annotation across rows is assumed to represent complex bracket definitions.
@const-ae
Copy link
Owner

In the new v.0.3.0 release I have extended the capability of the package to put brackets at custom locations, where only xmin, xmax and y_position are provided. The new code for the example thus looks like this:

dat <- data.frame(Group = c("S1", "S1", "S2", "S2"),
                  Sub   = c("A", "B", "A", "B"),
                  Value = c(3,5,7,8))  

ggplot(dat, aes(Group, Value)) +
  geom_bar(aes(fill = Sub), stat="identity", position="dodge", width=.5) +
  geom_signif(y_position=c(5.3, 8.3), xmin=c(0.8, 1.8), xmax=c(1.2, 2.2),
              annotation=c("**", "NS"), tip_length=0) +
  geom_signif(comparisons=list(c("S1", "S2")),
              y_position = 9.3, tip_length = 0, vjust=0.2) +
  scale_fill_manual(values = c("grey80", "grey20"))

result

This avoids the unnecessary complicated definition of the data.frame and aes in the geom_signif call.

I will close this issue, but you can re-open it if I missed anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants