const-ae/ggsignif

Warning message: Computation failed in `stat_signif()`: missing value where TRUE/FALSE needed

Saadi4469 opened this issue · 5 comments

I am getting this error while running the following code, this is the first time I created a code via reprex, so I hope it works. Due to this error, the p values don't show plus the box plots don't show. Can you please help with this? Since, I am not using the sample data, I am not able to use reprex, hence I am also uploading the dataset.

VIC_vs_PCA_SC_2004.zip

Thank you,

```{r setup, include=FALSE}
knitr::opts_chunk$set(
	echo = FALSE,
	message = FALSE,
	warning = FALSE,
	comment = NULL
)
library(tidyverse)
library(ggpubr)
library(htmlTable)
library(reprex)
library(plotly)
VIC_vs_PCA_SC_2004 <- read_csv("VIC_vs_PCA_SC_2004.csv")
df_2004 = VIC_vs_PCA_SC_2004
df_2004$GRID_CODE = factor(df_2004$GRID_CODE)
library(lubridate)
df_2004$Date = as.Date(df_2004$T, format = "%m/%d/%Y")

df_2004$Month = lubridate::month(df_2004$Date, label = TRUE, abbr=FALSE)
df_2004$Day = lubridate::day(df_2004$Date)

plot_kw_test_June_2004 = function(dframe, MONTH){
  # 1. Gather Columns to create long data frame
  Month_data = dframe %>%
    select(20, 19, 6, 18, 8, 14, 9, 15, 10, 16, 11, 17) %>%
    filter(Month == MONTH) %>%
    droplevels() %>% 
    gather(key = Type, value = Value, - Month, -Date) %>% 
    mutate(Type=factor(Type))

  # 2. Reorder levels of Type
  Month_data$Type = factor(Month_data$Type,
                           levels = c("VIC_SC_04","PCA_SC_04",
                                      "VIC_SCB2_04", "PCA_SCB2_04",
                                      "VIC_SCB3_04", "PCA_SCB3_04",
                                      "VIC_SCB4_04", "PCA_SCB4_04",
                                      "VIC_SCB5_04", "PCA_SCB5_04"))
  # 3. Create plot
  Month_data %>% ggplot(aes(x = Type, y = Value)) +
  geom_boxplot(aes(fill=Type)) +
    ylim(0,1.5)+
  geom_signif(comparisons = list(c("VIC_SC_04", "PCA_SC_04"),
                                    c("VIC_SCB2_04", "PCA_SCB2_04"),
                                    c("VIC_SCB3_04", "PCA_SCB3_04"),
                                    c("VIC_SCB4_04", "PCA_SCB4_04"),
                                    c("VIC_SCB5_04", "PCA_SCB5_04")),
              textsize=3,
              step_increase=0.05,
              test = kruskal.test) +
    theme(axis.text.x = element_text(angle = 90), legend.position = "none") +
    labs(x = "", y = "Snow Cover Fraction Value",
         title = paste("KRUSKAL test for Distributions of SC and PCA for ", MONTH , lubridate::year(Month_data$Date)))
}

plot_kw_test_June_2004(dframe = df_2004, MONTH = "June")
plot_kw_test_June_2004(dframe = df_2004, MONTH = "July")

Hi Saadi4496,

I am sorry. But I cannot debug your code for you. The error shouldn't depend on a specific dataset. Please try to extract a minimal example, that creates the error. For more help see https://stackoverflow.com/help/minimal-reproducible-example

Best,
Constantin

I was able to fix the issue, the problem was with one of pairs.

Cheers!

Great. Happy to hear that you found the solution 🎉

Hi, Saadi 4469,

I have a similar problem, I am inclined to just remove the problematic pairs. But perhaps you can tell me what was your solution?

I could not find a problem in my data when I ran into this issue, either when getting "missing value where TRUE/FALSE needed" or "not enough 'y' observations." Eventually, I figured out that it had to do with the naming of the comparisons, which have to match x-axis categories exactly (I had mis-typed one of them), and nothing to do with the number of y observations or missing values. I think writing a more helpful error message would be great here.