Computation failed in `stat_signif()`: missing value where TRUE/FALSE needed
Saadi4469 opened this issue · 2 comments
Saadi4469 commented
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?
Thank you,
``` r
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.0.3
#> Warning: package 'tidyr' was built under R version 4.0.3
#> Warning: package 'readr' was built under R version 4.0.3
#> Warning: package 'forcats' was built under R version 4.0.3
library(ggpubr)
#> Warning: package 'ggpubr' was built under R version 4.0.3
library(htmlTable)
#> Warning: package 'htmlTable' was built under R version 4.0.3
library(reprex)
#> Warning: package 'reprex' was built under R version 4.0.3
library(plotly)
#> Warning: package 'plotly' was built under R version 4.0.3
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
VIC_vs_PCA_SC_2004 <- read_csv("VIC_vs_PCA_SC_2004.csv")
#> Error: 'VIC_vs_PCA_SC_2004.csv' does not exist in current working directory ('C:/Users/saadb/AppData/Local/Temp/Rtmp29p0Ac/reprexf7823442ff6').
df_2004 = VIC_vs_PCA_SC_2004
#> Error in eval(expr, envir, enclos): object 'VIC_vs_PCA_SC_2004' not found
df_2004$GRID_CODE = factor(df_2004$GRID_CODE)
#> Error in factor(df_2004$GRID_CODE): object 'df_2004' not found
library(lubridate)
#> Warning: package 'lubridate' was built under R version 4.0.3
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
df_2004$Date = as.Date(df_2004$T, format = "%m/%d/%Y")
#> Error in as.Date(df_2004$T, format = "%m/%d/%Y"): object 'df_2004' not found
df_2004$Month = lubridate::month(df_2004$Date, label = TRUE, abbr=FALSE)
#> Error in lubridate::month(df_2004$Date, label = TRUE, abbr = FALSE): object 'df_2004' not found
df_2004$Day = lubridate::day(df_2004$Date)
#> Error in lubridate::day(df_2004$Date): object 'df_2004' not found
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")
#> Error in eval(lhs, parent, parent): object 'df_2004' not found
plot_kw_test_June_2004(dframe = df_2004, MONTH = "July")
#> Error in eval(lhs, parent, parent): object 'df_2004' not found
Created on 2020-12-03 by the reprex package (v0.3.0)
Saadi4469 commented
I had to close the question as the reprex didn't render the code properly
Saadi4469 commented
I will post another question, after I fix the issue