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

A modification suggestion for stat_compare_means #594

Open
AnkingLin opened this issue Dec 23, 2023 · 0 comments
Open

A modification suggestion for stat_compare_means #594

AnkingLin opened this issue Dec 23, 2023 · 0 comments

Comments

@AnkingLin
Copy link

In utilities_label.R:

# Check label coordinates for each group
#:::::::::::::::::::::::::::::::::::::::::
# coord.values: label coordinate for each group. If too short, they are recycled.
# group.id the id of groups as returned by ggplot_build()
.group_coord <- function(coord.values, group.id){
  if(!.is_empty(coord.values)){
    coord.values <- ifelse(length(coord.values) >= group.id,
                           coord.values[group.id], coord.values[1])
  }
  coord.values
}

this line

    coord.values <- ifelse(length(coord.values) >= group.id,
                           coord.values[group.id], coord.values[1])

should be changed to:

    coord.values <- ifelse(length(coord.values) >= group.id & group.id>0,
                           coord.values[group.id], coord.values[1])

in order to avoid passing in a group.id of 0 because the group data x contains 0, then causing an incredible error.(which confused me all night :-)


The problem can be reproduced like this:
First,generate group data with 0 in x (any x in (-2,1) can lead to this problem):

> data
   x   y group
1  0 1.1     A
2  0 1.2     A
3  0 1.3     A
4  0 1.4     A
5  3 1.5     A
6  3 1.6     A
7  3 1.7     A
8  3 1.8     A
9  0 1.1     B
10 0 1.2     B
11 0 1.3     B
12 0 1.4     B
13 3 1.5     B
14 3 1.6     B
15 3 1.7     B
16 3 1.8     B

Then have a simple plot:

> 
ggplot(data,aes(x=x,y=y,color=group))+
geom_point()+
stat_compare_means(label = 'p.signif')

And you get it:

Warning message:
Computation failed in `stat_compare_means()`
Caused by error in `purrr::map()`:
ℹ In index: 1.
Caused by error in `.check_npc_coord()`:
! '*.npc coord for x axis should be either a numeric value in [0-1] or a character strings including one of right, left, center, centre, middle 
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

1 participant